C# code compile problem.

Gast #1915610
Lesenswert?
• ▲
▼
Liebe leute ich kann diesen code mit c# 2010 express nicht compilen
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Windows.Forms;
9
using System.Runtime.InteropServices;
10

11
namespace LED_Display
12
{
13
    public partial class Form1 : Form
14
    {
15
        private Bitmap myBitmap;
16
        int i = 0;
17
        int j = 0;
18

19
        public byte[] SendData = new byte[1];
20

21
        public class Win32APICall
22
        {
23

24

25
            [DllImport("gdi32.dll", EntryPoint = "DeleteDC")]
26
            public static extern IntPtr DeleteDC(IntPtr hdc);
27

28
            [DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
29
            public static extern IntPtr DeleteObject(IntPtr hObject);
30

31
            [DllImport("gdi32.dll", EntryPoint = "BitBlt")]
32
            public static extern bool BitBlt(IntPtr hdcDest, int nXDest,
33
                int nYDest, int nWidth, int nHeight, IntPtr hdcSrc,
34
                int nXSrc, int nYSrc, int dwRop);
35

36
            [DllImport("gdi32.dll", EntryPoint = "CreateCompatibleBitmap")]
37
            public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,
38
                int nWidth, int nHeight);
39

40
            [DllImport("gdi32.dll", EntryPoint = "CreateCompatibleDC")]
41
            public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
42

43
            [DllImport("gdi32.dll", EntryPoint = "SelectObject")]
44
            public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobjBmp);
45

46
            [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
47
            public static extern IntPtr GetDesktopWindow();
48

49
            [DllImport("user32.dll", EntryPoint = "GetDC")]
50
            public static extern IntPtr GetDC(IntPtr hWnd);
51

52
            [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
53
            public static extern int GetSystemMetrics(int nIndex);
54

55
            [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
56
            public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
57

58
            public static Bitmap GetDesktop()
59
            {
60
                IntPtr hBmp;
61
                IntPtr hdcScreen = GetDC(GetDesktopWindow());
62
                IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);
63

64
                int screenX;
65
                int screenY;
66

67
                screenX = GetSystemMetrics(0) ;
68
                screenY = GetSystemMetrics(1) ;
69

70
                hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);
71

72
                if (hBmp != IntPtr.Zero)
73
                {
74
                    IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp);
75
                    //BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);
76

77
                    BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);
78

79
                    SelectObject(hdcCompatible, hOldBmp);
80
                    DeleteDC(hdcCompatible);
81
                    ReleaseDC(GetDesktopWindow(), hdcScreen);
82

83
                    Bitmap bmp = System.Drawing.Image.FromHbitmap(hBmp);
84

85
                    DeleteObject(hBmp);
86
                    GC.Collect();
87

88
                    return bmp;
89
                }
90

91
                return null;
92
            }
93

94
            
95
        }
96

97

98
        public Form1()
99
        {
100
            InitializeComponent();
101
        }
102

103
        private void Form1_Load(object sender, EventArgs e)
104
        {
105
            serialPort1.Open();
106
        }
107

108
        private void led_send()
109
        {
110

111
            myBitmap = Win32APICall.GetDesktop();
112

113
            //Graphicsオブジェクトの作成
114
             Graphics g = groupBox1.CreateGraphics();
115

116

117
            for (int y = 0; y < 32; y++)
118
            {
119
                j = j + 7;
120

121
                for (int x = 0; x < 32; x++)
122
                {
123

124
                    i = i + 7;
125
                    try
126
                    {
127

128
                        Color myColor = myBitmap.GetPixel(MousePosition.X + (31 - x) * (int)(numericUpDown1.Value), MousePosition.Y + y * (int)(numericUpDown1.Value));
129

130
              //Brushオブジェクトの作成
131
                          SolidBrush b = new SolidBrush(myColor);
132

133
                        //(10,20,100,80)の長方形を塗りつぶす
134
                          g.FillRectangle(b, 240 - i, 10 + j, 5, 5);
135

136
                        //Color myColor2 = myBitmap.GetPixel(MousePosition.X, MousePosition.Y);
137
                        //textBox1.Text = myColor2.R.ToString();
138
                        //textBox2.Text = myColor2.G.ToString();
139
                        //textBox3.Text = myColor2.B.ToString();
140

141
                        if (radioButton1.Checked)
142
                        {
143
                            SendData[0] = Convert.ToByte(myColor.R);
144
                        }
145
                        if (radioButton2.Checked)
146
                        {
147
                            SendData[0] = Convert.ToByte(myColor.G);
148
                        }
149
                        if (radioButton3.Checked)
150
                        {
151
                            SendData[0] = Convert.ToByte(myColor.B);
152
                        }
153

154
                        serialPort1.Write(SendData, 0, 1);//送信
155
                    }
156
                    catch
157
                    {
158
                    }
159

160
                }
161

162
                i = 0;
163
            }
164

165
            j = 0;
166

167
        }
168
        private void timer1_Tick(object sender, EventArgs e)
169
        {
170
            led_send();
171
        }
172
    }
173
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren