Preface
With the development of the business, applications can no longer meet user needs in some specific scenarios by displaying information on one monitor. How do we move multiple forms in the home screen running program to display at each extended screen position? What is C# implemented in? The following describes how C# is implemented using the Screen class.
detailed
Screen is a class under , which represents one or more display devices on a single system.
property
name | describe |
---|---|
AllScreens | Get all monitors on the system |
Bounds | Get the displayed boundary |
Primary | Whether the display is a monitor |
PrimaryScreen | Get the main monitor |
WorkingArea | The monitor's workspace |
method
The following table is some commonly used methods:
name | describe |
---|---|
FromControl(Control) | Retrieves the display that contains the largest portion of the specified control. |
GetBounds(Control) | Retrieves the boundary of the display containing the largest portion of the specified control. |
GetWorkingArea(Control) | Retrieves the display workspace that contains the largest area of the specified control. |
Notice:Screen is only available for Windows desktop applications below .NET 4.8.1 or later.
Example
This example displays the product in the second display screen and then scans the product. This allows the operator to check product information more clearly. The example also uses more C# event knowledge points.
Parameters are used to pass information
using System; using ; namespace { /// <summary> /// Event parameters /// </summary> public class SyncEventArg : EventArgs { /// <summary> /// Product Code /// </summary> public string ProductNo { get; set; } /// <summary> /// Product Picture /// </summary> public Image ProductImage { get; set; } } }
Auxiliary display interface
using System; using ; namespace { public partial class SecondForm : Form { public SecondForm() { InitializeComponent(); } /// <summary> /// Response to event processing /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal void SysncTextChaned(object sender, EventArgs e) { try { //Fetch the text from the main form SyncEventArg arg = e as SyncEventArg; = ; = ; } catch { } } } }
Program main interface
using System; using ; using ; namespace { public partial class MainForm : Form { //Use the default event to process delegates and define the message publisher event public event EventHandler SendMsgEvent; /// <summary> /// /// </summary> public MainForm() { InitializeComponent(); } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { try { SecondForm secondForm = new SecondForm(); // Event subscription SendMsgEvent += ; // Get all monitors on the system Screen[] screens = ; //Judge multi-screen if ( >1 ) { // Get the second screen Screen screen = screens[1]; = ; // On the second screen, display the second form = ; } // Display auxiliary interface (); } catch { } } /// <summary> /// Text input box enter event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TextBoxProductNo_KeyDown(object sender, KeyEventArgs e) { try { if ( != ) { return; } if (()) { return; } Image image = (""); // Event trigger notification SendMsgEvent(this, new SyncEventArg() { ProductNo = , ProductImage = image }); } catch(Exception ex) { (); } } } }
summary
The above is to use the Screen class in C# to implement different interfaces of desktop applications to display information on multiple monitors. I hope that through the simple cases in this article, we can expand our thinking.
This is the end of this article about how to implement multi-screen display in detail in C# applications. For more related C# multi-screen display content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!