Drawing
How do I use Drawing
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: frmColor.cs
Copy
86 private void InitializeComponent()
87 {
88 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ColorInput));
89 this.Blue = new System.Windows.Forms.TextBox();
90 this.label4 = new System.Windows.Forms.Label();
91 this.Green = new System.Windows.Forms.TextBox();
92 this.label3 = new System.Windows.Forms.Label();
93 this.Red = new System.Windows.Forms.TextBox();
94 this.label2 = new System.Windows.Forms.Label();
95 this.label1 = new System.Windows.Forms.Label();
96 this.Cancel = new System.Windows.Forms.Button();
97 this.OK = new System.Windows.Forms.Button();
98 this.SuspendLayout();
99 //
100 // Blue
101 //
102 this.Blue.Location = new System.Drawing.Point(103, 112);
103 this.Blue.Name = "Blue";
104 this.Blue.Size = new System.Drawing.Size(100, 20);
105 this.Blue.TabIndex = 17;
106 ////
107 // label4
108 //
109 this.label4.ForeColor = System.Drawing.Color.Blue;
110 this.label4.Location = new System.Drawing.Point(32, 112);
111 this.label4.Name = "label4";
112 this.label4.Size = new System.Drawing.Size(32, 16);
113 this.label4.TabIndex = 16;
114 this.label4.Text = "Blue";
115 // //
116 // // Green
117 // //
118 this.Green.Location = new System.Drawing.Point(103, 80);
119 this.Green.Name = "Green";
120 this.Green.Size = new System.Drawing.Size(100, 20);
121 this.Green.TabIndex = 15;
122 //
123 // // label3
124 // //
125 this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
126 this.label3.Location = new System.Drawing.Point(32, 80);
127 this.label3.Name = "label3";
128 this.label3.Size = new System.Drawing.Size(32, 16);
129 this.label3.TabIndex = 14;
130 this.label3.Text = "Green";
131 //
132 // // Red
133 // //
134 this.Red.Location = new System.Drawing.Point(103, 48);
135 this.Red.Name = "Red";
136 this.Red.Size = new System.Drawing.Size(100, 20);
137 this.Red.TabIndex = 13;
138 // //
139 // // label2
140 // //
141 this.label2.ForeColor = System.Drawing.Color.Red;
142 this.label2.Location = new System.Drawing.Point(32, 48);
143 this.label2.Name = "label2";
144 this.label2.Size = new System.Drawing.Size(32, 16);
145 this.label2.TabIndex = 12;
146 this.label2.Text = "Red";
147 //
148 // // label1
149 // //
150 this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
151 this.label1.ForeColor = System.Drawing.Color.Blue;
152 this.label1.Location = new System.Drawing.Point(16, 16);
153 this.label1.Name = "label1";
154 this.label1.Size = new System.Drawing.Size(281, 24);
155 this.label1.TabIndex = 11;
156 this.label1.Text = "Nhập các giá trị màu từ -255 đến 255";
157 // this.label1.Click += new System.EventHandler(this.label1_Click);
158 // //
159 // // Cancel
160 // //
161 this.Cancel.Location = new System.Drawing.Point(176, 178);
162 this.Cancel.Name = "Cancel";
163 this.Cancel.Size = new System.Drawing.Size(75, 23);
164 this.Cancel.TabIndex = 9;
165 this.Cancel.Text = "Bỏ qua";
166 //
167 // // OK
168 // //
169 this.OK.Location = new System.Drawing.Point(19, 178);
170 this.OK.Name = "OK";
171 this.OK.Size = new System.Drawing.Size(75, 23);
172 this.OK.TabIndex = 10;
173 this.OK.Text = "Đồng ý";
174 // this.OK.Click += new System.EventHandler(this.OK_Click);
175 //
176 // ColorInput
177 //
178 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
179 this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
180 this.ClientSize = new System.Drawing.Size(309, 226);
181 this.Controls.Add(this.Blue);
182 this.Controls.Add(this.label4);
183 this.Controls.Add(this.Green);
184 this.Controls.Add(this.label3);
185 this.Controls.Add(this.Red);
186 this.Controls.Add(this.label2);
187 this.Controls.Add(this.label1);
188 this.Controls.Add(this.OK);
189 this.Controls.Add(this.Cancel);
190 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
191 this.Name = "ColorInput";
192 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
193 this.Text = "CHON MAU";
194 //this.Load += new System.EventHandler(this.ColorInput_Load);
195 this.ResumeLayout(false);
196 this.PerformLayout();
197
198 }
File name: frmMain.cs
Copy
59 private void InitializeComponent()
60 {
61 this.components = new System.ComponentModel.Container();
62 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
63 this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
64 this.menuItem1 = new System.Windows.Forms.MenuItem();
65 this.FileLoad = new System.Windows.Forms.MenuItem();
66 this.FileSave = new System.Windows.Forms.MenuItem();
67 this.FileExit = new System.Windows.Forms.MenuItem();
68 this.menuItem4 = new System.Windows.Forms.MenuItem();
69 this.FilterGrayScale = new System.Windows.Forms.MenuItem();
70 this.FilterColor = new System.Windows.Forms.MenuItem();
71 this.menuItem3 = new System.Windows.Forms.MenuItem();
72 this.EmbossLaplacian = new System.Windows.Forms.MenuItem();
73 this.EdgeDetectQuick = new System.Windows.Forms.MenuItem();
74 this.SuspendLayout();
75 //
76 // mainMenu1
77 //
78 this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
79 this.menuItem1,
80 this.menuItem4,
81 this.menuItem3});
82 //
83 // menuItem1
84 //
85 this.menuItem1.Index = 0;
86 this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
87 this.FileLoad,
88 this.FileSave,
89 this.FileExit});
90 this.menuItem1.Text = "File";
91 //this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
92 //
93 // FileLoad
94 //
95 this.FileLoad.Index = 0;
96 this.FileLoad.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
97 this.FileLoad.Text = "Mở file";
98 this.FileLoad.Click += new System.EventHandler(this.File_Load);
99 //
100 // FileSave
101 //
102 this.FileSave.Index = 1;
103 this.FileSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
104 this.FileSave.Text = "Lưu file";
105 this.FileSave.Click += new System.EventHandler(this.File_Save);
106 //
107 // FileExit
108 //
109 this.FileExit.Index = 2;
110 this.FileExit.Text = "Thoát";
111 this.FileExit.Click += new System.EventHandler(this.File_Exit);
112 //
113 // menuItem4
114 //
115 this.menuItem4.Index = 1;
116 this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
117 this.FilterGrayScale,
118 this.FilterColor});
119 this.menuItem4.Text = "Biến đổi màu";
120 //
121 // FilterGrayScale
122 //
123 this.FilterGrayScale.Index = 0;
124 this.FilterGrayScale.Text = "Xám";
125 this.FilterGrayScale.Click += new System.EventHandler(this.Filter_GrayScale);
126 //
127 // FilterColor
128 //
129 this.FilterColor.Index = 1;
130 this.FilterColor.Text = "Màu";
131 this.FilterColor.Click += new System.EventHandler(this.Filter_Color);
132 //
133 // menuItem3
134 //
135 this.menuItem3.Index = 2;
136 this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
137 this.EmbossLaplacian,
138 this.EdgeDetectQuick});
139 this.menuItem3.Text = "Phát hiện biên";
140 //this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
141 //
142 // EmbossLaplacian
143 //
144 this.EmbossLaplacian.Index = 0;
145 this.EmbossLaplacian.Text = "Laplacian_Emboss";
146 this.EmbossLaplacian.Click += new System.EventHandler(this.OnEmbossLaplacian);
147 //
148 // EdgeDetectQuick
149 //
150 this.EdgeDetectQuick.Index = 1;
151 this.EdgeDetectQuick.Text = "EdgeDetectQuick";
152 this.EdgeDetectQuick.Click += new System.EventHandler(this.OnEdgeDetectQuick);
153 //
154 // frmMain
155 //
156 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
157 this.BackColor = System.Drawing.SystemColors.ControlLightLight;
158 this.BackgroundImage = global::CSharpFilters.Properties.Resources.Daewoo;
159 this.ClientSize = new System.Drawing.Size(349, 237);
160 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
161 this.Menu = this.mainMenu1;
162 this.Name = "frmMain";
163 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
164 this.Text = "Xu ly anh";
165 //this.Load += new System.EventHandler(this.Form1_Load);
166 this.ResumeLayout(false);
167
168 }
File name: frmProduct.cs
Copy
96 private void btnSave_Click(object sender, EventArgs e)
97 {
98 if (txtProductName.Text == "")
99 {
100 MessageBox.Show("Please enter product name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
101 txtProductName.Focus();
102 return;
103 }
104 if (cmbCategory.Text == "")
105 {
106 MessageBox.Show("Please select category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
107 cmbCategory.Focus();
108 return;
109 }
110 if (cmbSubCategory.Text == "")
111 {
112 MessageBox.Show("Please select sub category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
113 cmbSubCategory.Focus();
114 return;
115 }
116 if (txtPrice.Text == "")
117 {
118 MessageBox.Show("Please enter price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
119 txtPrice.Focus();
120 return;
121 }
122 try
123 {
124 con = new SqlConnection(cs.DBConn);
125 con.Open();
126 string ct = "select ProductName from Product where ProductName='" + txtProductName.Text + "'";
127
128 cmd = new SqlCommand(ct);
129 cmd.Connection = con;
130 rdr = cmd.ExecuteReader();
131
132 if (rdr.Read())
133 {
134 MessageBox.Show("Product Name Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
135 txtProductName.Text = "";
136 txtProductName.Focus();
137
138
139 if ((rdr != null))
140 {
141 rdr.Close();
142 }
143 return;
144 }
145 auto();
146 con = new SqlConnection(cs.DBConn);
147 con.Open();
148 string cb = "insert into Product(ProductID,ProductName,CategoryID,SubCategoryID,Features,Price,Image) VALUES ('" + txtProductID.Text + "','" + txtProductName.Text + "'," + txtCategoryID.Text+ "," + txtSubCategoryID.Text+ ",@d1,"+ txtPrice.Text +",@d2)";
149 cmd = new SqlCommand(cb);
150 cmd.Connection = con;
151 cmd.Parameters.AddWithValue("@d1", txtFeatures.Text);
152 MemoryStream ms = new MemoryStream();
153 Bitmap bmpImage = new Bitmap(pictureBox1.Image);
154 bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
155 byte[] data = ms.GetBuffer();
156 SqlParameter p = new SqlParameter("@d2", SqlDbType.Image);
157 p.Value = data;
158 cmd.Parameters.Add(p);
159 cmd.ExecuteReader();
160 con.Close();
161 MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
162 Autocomplete();
163 btnSave.Enabled = false;
164 }
165 catch (Exception ex)
166 {
167 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
168 }
169 }
File name: frmProduct.cs
Copy
244 private void btnUpdate_Click(object sender, EventArgs e)
245 {
246 if (txtProductName.Text == "")
247 {
248 MessageBox.Show("Please enter product name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
249 txtProductName.Focus();
250 return;
251 }
252 if (cmbCategory.Text == "")
253 {
254 MessageBox.Show("Please select category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
255 cmbCategory.Focus();
256 return;
257 }
258 if (cmbSubCategory.Text == "")
259 {
260 MessageBox.Show("Please select sub category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
261 cmbSubCategory.Focus();
262 return;
263 }
264 if (txtPrice.Text == "")
265 {
266 MessageBox.Show("Please enter price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
267 txtPrice.Focus();
268 return;
269 }
270 try
271 {
272
273 con = new SqlConnection(cs.DBConn);
274 con.Open();
275 string cb = "Update product set ProductName='" + txtProductName.Text + "',CategoryID=" + txtCategoryID.Text + ",SubCategoryID=" + txtSubCategoryID.Text + ",Features=@d1,price=" + txtPrice.Text + ",Image=@d2 Where ProductID='" + txtProductID.Text + "'";
276 cmd = new SqlCommand(cb);
277 cmd.Connection = con;
278 cmd.Parameters.AddWithValue("@d1", txtFeatures.Text);
279 MemoryStream ms = new MemoryStream();
280 Bitmap bmpImage = new Bitmap(pictureBox1.Image);
281 bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
282 byte[] data = ms.GetBuffer();
283 SqlParameter p = new SqlParameter("@d2", SqlDbType.Image);
284 p.Value = data;
285 cmd.Parameters.Add(p);
286 cmd.ExecuteReader();
287 con.Close();
288 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
289 Autocomplete();
290 btnUpdate.Enabled = false;
291 }
292 catch (Exception ex)
293 {
294 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
295 }
296 }
File name: ChatBot.cs
Copy
204 private void menuButton_Click(object sender, EventArgs e)
205 {
206 contextMenuStrip1.Show(menuButton, new System.Drawing.Point(0, -contextMenuStrip1.Size.Height));
207 }
Drawing 127 lượt xem
Gõ tìm kiếm nhanh...