{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/288283132","pull_request_review_id":242897370,"id":288283132,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI4ODI4MzEzMg==","diff_hunk":"@@ -491,5 +493,33 @@ public void DebuggerAttributesAreValid()\n             DebuggerAttributes.ValidateDebuggerDisplayReferences(Color.Aquamarine);\n             DebuggerAttributes.ValidateDebuggerDisplayReferences(Color.FromArgb(4, 3, 2, 1));\n         }\n+\n+        [Fact]\n+        public void UserPreferenceChangingEventTest()\n+        {\n+            int element = 12; // Win32SystemColors.AppWorkSpace.\n+            Color color = System.Drawing.SystemColors.AppWorkspace;\n+\n+            // A call to ToArgb is necessary before changing the system colors because it initializes the knownColorTable.\n+            int oldColor = color.ToArgb();\n+\n+            try\n+            {\n+                // choosing a random int instead of a defined color to avoid failures for users with that defined color as system color.\n+                Assert.Equal(1, SetSysColors(1, new int[] { element }, new int[] { 89 }));","path":"src/System.Drawing.Primitives/tests/ColorTests.cs","position":25,"original_position":26,"commit_id":"89a1080a47644c9e4515de39332ca23327a221b9","original_commit_id":"51d995f19dd869662a3f4874aeb099bfaddb6751","user":{"login":"ericstj","id":8918108,"node_id":"MDQ6VXNlcjg5MTgxMDg=","avatar_url":"https://avatars3.githubusercontent.com/u/8918108?v=4","gravatar_id":"","url":"https://api.github.com/users/ericstj","html_url":"https://github.com/ericstj","followers_url":"https://api.github.com/users/ericstj/followers","following_url":"https://api.github.com/users/ericstj/following{/other_user}","gists_url":"https://api.github.com/users/ericstj/gists{/gist_id}","starred_url":"https://api.github.com/users/ericstj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericstj/subscriptions","organizations_url":"https://api.github.com/users/ericstj/orgs","repos_url":"https://api.github.com/users/ericstj/repos","events_url":"https://api.github.com/users/ericstj/events{/privacy}","received_events_url":"https://api.github.com/users/ericstj/received_events","type":"User","site_admin":false},"body":"Why not set a specific color and then Assert that the value you get is equal? \r\n\r\n[COLORREF](https://docs.microsoft.com/en-us/windows/desktop/gdi/colorref) is defined as 0x00bbggrr, so you just need to encode a color to that integer and then check it.  You should also check that the existing value isn't the color you're changing it to, otherwise your assert will fail.\r\n\r\nAlso, since SetSysColors is expecting BGR format instead of RGB the call below in the finally does the wrong thing.","created_at":"2019-05-28T20:15:35Z","updated_at":"2019-05-28T20:15:35Z","html_url":"https://github.com/dotnet/corefx/pull/37853#discussion_r288283132","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/37853","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/288283132"},"html":{"href":"https://github.com/dotnet/corefx/pull/37853#discussion_r288283132"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/37853"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/37853","id":280973959,"node_id":"MDExOlB1bGxSZXF1ZXN0MjgwOTczOTU5","html_url":"https://github.com/dotnet/corefx/pull/37853","diff_url":"https://github.com/dotnet/corefx/pull/37853.diff","patch_url":"https://github.com/dotnet/corefx/pull/37853.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/37853","number":37853,"state":"open","locked":false,"title":"Using reflection to add handler for user preference events","user":{"login":"Anipik","id":10516582,"node_id":"MDQ6VXNlcjEwNTE2NTgy","avatar_url":"https://avatars1.githubusercontent.com/u/10516582?v=4","gravatar_id":"","url":"https://api.github.com/users/Anipik","html_url":"https://github.com/Anipik","followers_url":"https://api.github.com/users/Anipik/followers","following_url":"https://api.github.com/users/Anipik/following{/other_user}","gists_url":"https://api.github.com/users/Anipik/gists{/gist_id}","starred_url":"https://api.github.com/users/Anipik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anipik/subscriptions","organizations_url":"https://api.github.com/users/Anipik/orgs","repos_url":"https://api.github.com/users/Anipik/repos","events_url":"https://api.github.com/users/Anipik/events{/privacy}","received_events_url":"https://api.github.com/users/Anipik/received_events","type":"User","site_admin":false},"body":"Fixes https://github.com/dotnet/corefx/issues/36642\r\n\r\nI tested it locally with changing the contrast of the machine, and the event handler is getting invoked.\r\n\r\nCode snippet to test the change\r\n\r\n``` c#\r\nusing Microsoft.Win32;\r\nusing System;\r\nusing System.Reflection;\r\n\r\nnamespace System.Drawing\r\n{\r\n    static internal class KnownColorTable\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            Type systeEventsType = Type.GetType(\"Microsoft.Win32.SystemEvents, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", throwOnError: false);\r\n            EventInfo upEventInfo = systeEventsType?.GetEvent(\"UserPreferenceChanging\", BindingFlags.Public | BindingFlags.Static);\r\n\r\n            if (upEventInfo != null)\r\n            {\r\n                Type userPrefChangingDelegateType = Type.GetType(\"Microsoft.Win32.UserPreferenceChangingEventHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", throwOnError: false);\r\n                MethodInfo mi = Type.GetType(\"System.Drawing.KnownColorTable\")?.GetMethod(\"OnUserPreferenceChanging\", BindingFlags.NonPublic | BindingFlags.Static);\r\n                Delegate handler = Delegate.CreateDelegate(userPrefChangingDelegateType, mi);\r\n                upEventInfo.AddEventHandler(null, handler);\r\n            }\r\n            while (true) { }\r\n        }\r\n\r\n        private static void OnUserPreferenceChanging(object sender, EventArgs args)\r\n        {\r\n            PropertyInfo categoryProperty = args.GetType()?.GetProperty(\"Category\", BindingFlags.Instance | BindingFlags.Public);\r\n\r\n            if (categoryProperty == null)\r\n                return;\r\n\r\n            int propertyValue = (int)categoryProperty.GetValue(args);\r\n            if (propertyValue == 2) // UserPreferenceCategory.Color = 2\r\n            {\r\n                Console.WriteLine(\"Its Working\");\r\n            }\r\n        }\r\n    }\r\n\r\n}\r\n```\r\n\r\nI will try to test it with win forms app with my local version of corefx\r\n","created_at":"2019-05-21T22:39:01Z","updated_at":"2019-05-28T20:15:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82f650ab01c3fa23d92ecf21fa065ad3ed7d39e6","assignee":null,"assignees":[],"requested_reviewers":[{"login":"danmosemsft","id":6385855,"node_id":"MDQ6VXNlcjYzODU4NTU=","avatar_url":"https://avatars3.githubusercontent.com/u/6385855?v=4","gravatar_id":"","url":"https://api.github.com/users/danmosemsft","html_url":"https://github.com/danmosemsft","followers_url":"https://api.github.com/users/danmosemsft/followers","following_url":"https://api.github.com/users/danmosemsft/following{/other_user}","gists_url":"https://api.github.com/users/danmosemsft/gists{/gist_id}","starred_url":"https://api.github.com/users/danmosemsft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danmosemsft/subscriptions","organizations_url":"https://api.github.com/users/danmosemsft/orgs","repos_url":"https://api.github.com/users/danmosemsft/repos","events_url":"https://api.github.com/users/danmosemsft/events{/privacy}","received_events_url":"https://api.github.com/users/danmosemsft/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/37853/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/37853/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/37853/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/89a1080a47644c9e4515de39332ca23327a221b9","head":{"label":"Anipik:systemEvents","ref":"systemEvents","sha":"89a1080a47644c9e4515de39332ca23327a221b9","user":{"login":"Anipik","id":10516582,"node_id":"MDQ6VXNlcjEwNTE2NTgy","avatar_url":"https://avatars1.githubusercontent.com/u/10516582?v=4","gravatar_id":"","url":"https://api.github.com/users/Anipik","html_url":"https://github.com/Anipik","followers_url":"https://api.github.com/users/Anipik/followers","following_url":"https://api.github.com/users/Anipik/following{/other_user}","gists_url":"https://api.github.com/users/Anipik/gists{/gist_id}","starred_url":"https://api.github.com/users/Anipik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anipik/subscriptions","organizations_url":"https://api.github.com/users/Anipik/orgs","repos_url":"https://api.github.com/users/Anipik/repos","events_url":"https://api.github.com/users/Anipik/events{/privacy}","received_events_url":"https://api.github.com/users/Anipik/received_events","type":"User","site_admin":false},"repo":{"id":104249984,"node_id":"MDEwOlJlcG9zaXRvcnkxMDQyNDk5ODQ=","name":"corefx","full_name":"Anipik/corefx","private":false,"owner":{"login":"Anipik","id":10516582,"node_id":"MDQ6VXNlcjEwNTE2NTgy","avatar_url":"https://avatars1.githubusercontent.com/u/10516582?v=4","gravatar_id":"","url":"https://api.github.com/users/Anipik","html_url":"https://github.com/Anipik","followers_url":"https://api.github.com/users/Anipik/followers","following_url":"https://api.github.com/users/Anipik/following{/other_user}","gists_url":"https://api.github.com/users/Anipik/gists{/gist_id}","starred_url":"https://api.github.com/users/Anipik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anipik/subscriptions","organizations_url":"https://api.github.com/users/Anipik/orgs","repos_url":"https://api.github.com/users/Anipik/repos","events_url":"https://api.github.com/users/Anipik/events{/privacy}","received_events_url":"https://api.github.com/users/Anipik/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Anipik/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others. We welcome contributions.","fork":true,"url":"https://api.github.com/repos/Anipik/corefx","forks_url":"https://api.github.com/repos/Anipik/corefx/forks","keys_url":"https://api.github.com/repos/Anipik/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Anipik/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Anipik/corefx/teams","hooks_url":"https://api.github.com/repos/Anipik/corefx/hooks","issue_events_url":"https://api.github.com/repos/Anipik/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/Anipik/corefx/events","assignees_url":"https://api.github.com/repos/Anipik/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/Anipik/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/Anipik/corefx/tags","blobs_url":"https://api.github.com/repos/Anipik/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Anipik/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Anipik/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/Anipik/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Anipik/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/Anipik/corefx/languages","stargazers_url":"https://api.github.com/repos/Anipik/corefx/stargazers","contributors_url":"https://api.github.com/repos/Anipik/corefx/contributors","subscribers_url":"https://api.github.com/repos/Anipik/corefx/subscribers","subscription_url":"https://api.github.com/repos/Anipik/corefx/subscription","commits_url":"https://api.github.com/repos/Anipik/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/Anipik/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/Anipik/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/Anipik/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/Anipik/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/Anipik/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Anipik/corefx/merges","archive_url":"https://api.github.com/repos/Anipik/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Anipik/corefx/downloads","issues_url":"https://api.github.com/repos/Anipik/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/Anipik/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/Anipik/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/Anipik/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Anipik/corefx/labels{/name}","releases_url":"https://api.github.com/repos/Anipik/corefx/releases{/id}","deployments_url":"https://api.github.com/repos/Anipik/corefx/deployments","created_at":"2017-09-20T17:59:22Z","updated_at":"2019-05-23T22:44:09Z","pushed_at":"2019-05-28T19:58:07Z","git_url":"git://github.com/Anipik/corefx.git","ssh_url":"git@github.com:Anipik/corefx.git","clone_url":"https://github.com/Anipik/corefx.git","svn_url":"https://github.com/Anipik/corefx","homepage":"https://github.com/dotnet/core","size":213647,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"9963d520d38caf5318356a08c4a3b08f904d2b26","user":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":26295345,"node_id":"MDEwOlJlcG9zaXRvcnkyNjI5NTM0NQ==","name":"corefx","full_name":"dotnet/corefx","private":false,"owner":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/dotnet/corefx","description":"CoreFX is the foundational class libraries for .NET Core. It includes types for collections, file systems, console, JSON, XML, async and many others.","fork":false,"url":"https://api.github.com/repos/dotnet/corefx","forks_url":"https://api.github.com/repos/dotnet/corefx/forks","keys_url":"https://api.github.com/repos/dotnet/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefx/teams","hooks_url":"https://api.github.com/repos/dotnet/corefx/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefx/events","assignees_url":"https://api.github.com/repos/dotnet/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefx/tags","blobs_url":"https://api.github.com/repos/dotnet/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefx/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefx/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefx/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefx/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefx/subscription","commits_url":"https://api.github.com/repos/dotnet/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefx/merges","archive_url":"https://api.github.com/repos/dotnet/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefx/downloads","issues_url":"https://api.github.com/repos/dotnet/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefx/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefx/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/corefx/deployments","created_at":"2014-11-06T23:42:48Z","updated_at":"2019-05-28T19:27:41Z","pushed_at":"2019-05-28T20:03:17Z","git_url":"git://github.com/dotnet/corefx.git","ssh_url":"git@github.com:dotnet/corefx.git","clone_url":"https://github.com/dotnet/corefx.git","svn_url":"https://github.com/dotnet/corefx","homepage":"https://docs.microsoft.com/dotnet/core/","size":216214,"stargazers_count":16666,"watchers_count":16666,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4989,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":2619,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":4989,"open_issues":2619,"watchers":16666,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/37853"},"html":{"href":"https://github.com/dotnet/corefx/pull/37853"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/37853"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/37853/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/37853/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/37853/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/89a1080a47644c9e4515de39332ca23327a221b9"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"ericstj"}}