C # Winform multi-screen multi-display programming example

Source: Internet
Author: User

C # Winform multi-screen multi-display programming example

This article mainly introduces the C # Winform multi-screen multi-display programming example. This article provides code examples directly. For more information, see

There is a System in the middle of the window. windows. forms. the PictureBox control (the area of the control area is 1/4 of the window). When most areas of the control fall on one monitor, the control is not displayed on the other monitor, (This PictureBox control will be moved to the window area of the main display ).

Implementation Method:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

Using System;

Using System. Drawing;

Using System. Collections;

Using System. ComponentModel;

Using System. Windows. Forms;

Using System. Data;

Namespace WindowsApplication12

{

/// <Summary>

/// Summary description for Form1.

/// </Summary>

Public class Form1: System. Windows. Forms. Form

{

Private int tmpx = 0;

Private int tmpy = 0;

Private System. Windows. Forms. PictureBox pictureBox1;

/// <Summary>

/// Required designer variable.

/// </Summary>

Private System. ComponentModel. Container components = null;

System. Drawing. Rectangle [] ScreensRect;

Public Form1 ()

{

//

// Required for Windows Form Designer support

//

InitializeComponent ();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <Summary>

/// Clean up any resources being used.

/// </Summary>

Protected override void Dispose (bool disposing)

{

If (disposing)

{

If (components! = Null)

{

Components. Dispose ();

}

}

Base. Dispose (disposing );

}

# Region Windows Form Designer generated code

/// <Summary>

/// Required method for Designer support-do not modify

/// The contents of this method with the code editor.

/// </Summary>

Private void InitializeComponent ()

{

This. pictureBox1 = new System. Windows. Forms. PictureBox ();

This. SuspendLayout ();

//

// PictureBox1

//

This. pictureBox1.BackColor = System. Drawing. SystemColors. HotTrack;

This. pictureBox1.Location = new System. Drawing. Point (120, 88 );

This. pictureBox1.Name = "pictureBox1 ";

This. pictureBox1.Size = new System. Drawing. Size (248,176 );

This. pictureBox1.TabIndex = 0;

This. pictureBox1.TabStop = false;

//

// Form1

//

This. AutoScaleBaseSize = new System. Drawing. Size (5, 13 );

This. ClientSize = new System. Drawing. Size (504,357 );

This. Controls. Add (this. pictureBox1 );

This. Name = "Form1 ";

This. Text = "Form1 ";

This. MouseDown + = new System. Windows. Forms. MouseEventHandler (this. Form1_MouseDown );

This. Load + = new System. EventHandler (this. form#load );

This. MouseUp + = new System. Windows. Forms. MouseEventHandler (this. Form1_MouseUp );

This. ResumeLayout (false );

}

# Endregion

/// <Summary>

/// The main entry point for the application.

/// </Summary>

[STAThread]

Static void Main ()

{

Application. Run (new Form1 ());

}

Private void form=mousedown (object sender, System. Windows. Forms. MouseEventArgs e)

{

This. tmpx = e. X;

This. tmpy = e. Y;

This. MouseMove + = new System. Windows. Forms. MouseEventHandler (this. form1_MouseMove );

}

Private void form=mouseup (object sender, System. Windows. Forms. MouseEventArgs e)

{

This. MouseMove-= new System. Windows. Forms. MouseEventHandler (this. form1_MouseMove );

System. Drawing. Rectangle pictureBox1Rect = Screen. GetWorkingArea (pictureBox1 );

For (int I = 0; I <ScreensRect. Length; I ++)

{

If (ScreensRect [I]. X = pictureBox1Rect. X & ScreensRect [I]. Y = pictureBox1Rect. Y)

This. Location = new Point (ScreensRect [I]. X, pictureBox1Rect. Y );

}

// MessageBox. Show ("WorkingArea:" + re. ToString ());

}

Private void form=mousemove (object sender, MouseEventArgs e)

{

This. Location = new System. Drawing. Point (this. Location. X + e. X-this. tmpx, this. Location. Y + e. Y-this. tmpy );

}

Private void Form1_Load (object sender, System. EventArgs e)

{

Screen [] s = Screen. AllScreens;

ScreensRect = new Rectangle [s. Length];

For (int I = 0; I <s. Length; I ++)

{

ScreensRect [I] = s [I]. WorkingArea;

}

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.