The difference between wpf and winform

  When it comes to the difference between winform and wpf, most people may think that wpf has a beautiful interface. Winform can also be used in wpf. In most cases, there are no problems. In rare cases, problems may occur.

  Let's take a look:

       void FloatWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.Topmost = true;
            this.Left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - 300;
            this.Top = 300;
        }

  This is a piece of code from the wpf application. The intention of this code is obvious, that is, to position the floating form when it loads. During development and testing, there are no problems. We mainly test on PC. The test on the laptop is also a computer from a few years ago. One day, the company became rich and equipped with a computer with better performance. My colleague was going to bring it to tell customers about our software. Unexpectedly, when we installed it, we found that the floating window was missing. Colleagues' first reaction: the laptop is not set correctly. Later, I went to trace the code, including the log. Because on a build environment or on a user machine, you can't debug like you can in development. It turns out that the value of Left is much larger than the screen resolution. For example, if the screen resolution is 1024*768, the Left result obtained is nearly twice that of 1024. I can't help but be surprised.

  Later, the code was changed to the wpf version:

this.Left=SystemParameters.WorkArea.Width-300;

  This solved the problem. Why does this problem occur? wpf is hardware related, or winform has bugs in new devices? This issue has not been delved into, and it is necessary to maintain awe of the production environment. Who knows what kind of environment the code you write will run in.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325304237&siteId=291194637