Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of abnormal pop-up position of Popup in C #

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In view of how to solve the problem of abnormal Popup pop-up position in C #, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Solution method

Problem description

Use the Popup control as the pop-up box and use the relative position to pop up, that is, Placement= "Relative". The pop-up position is not consistent in different devices. For example, the following example.

Use the following code:

Display effect:

Cause analysis

This situation is mainly due to problems caused by different system settings of Windows. The pop-up box will change the pop-up reference point according to the menu position of the system.

How to view the settings:

Using the key combination "Win+R", bring up the "run" dialog box and enter "shell::: {80F3F1D5-FECA-45F3-BC32-752C152E456E}" in the text box.

Select other when you open it. It is found that most systems default to left hand on. But when some systems are artificially set to be turned on with the right hand, the pop-up position of the Popup is abnormal.

Solution method

Method 1. Modify the system configuration

(1) manually modify

Refer to the above

(2) modify through Win32 Api

[DllImport ("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)] public static extern bool SystemParametersInfoSet (uint action, uint uiParam, uint vparam, uint init); void SetMenuAlign () {/ / uiParam sets pop-up menu left alignment when false, true right alignment SystemParametersInfoSet (0x001C / * SPI_SETMENUDROPALIGNMENT*/, 0,0,0);}

Method 2. Adjust the code

Use Placement= "Absolute" to pop up Popup:

Calculate the relative position in cs:

Private void Popup1_Opened (object sender, EventArgs e) {Popup pop = sender as Popup; if (pop = = null) return; if (pop.PlacementTarget = = null) return; if (pop.Placement = = PlacementMode.Absolute) {var relative = pop.PlacementTarget.PointToScreen (new Point (0,0)) Pop.HorizontalOffset = relative.X + 80; pop.VerticalOffset = relative.Y +-100;}} this is the answer to the question about how to solve the problem of abnormal Popup pop-up position in C#. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to implement confirmation and submit by JavaScript

    This article is to share with you about how JavaScript implements the content submitted after confirmation. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look. Submit after confirmation and add the following code to the area

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report