当前位置:网站首页>C learning notes
C learning notes
2022-07-05 07:11:00 【mQ_ one billion eight hundred and forty-eight million one hundr】
Catalog
Randomly update label position
Change the window size
// adopt button1_click Click Change
private void button1_Click(object sender, EventArgs e)
{
//this.ClientSize = new System.Drawing.Size(300, 400);
//this.ClientSize = new Size(300, 400);// User area size
this.Size = new Size(300, 400);// The whole window size
this.button1.Size = new System.Drawing.Size(160, 150);//button1 size
}

Get window size
private void button1_Click(object sender, EventArgs e)
{
int w = this.Size.Width;
int h = this.Size.Height;
MessageBox.Show(" wide :" + w + " high :" + h);
}
Get button location
private void button1_Click(object sender, EventArgs e)
{
//int loc_x = this.button1.Location.X; // It can also be obtained in advance
//int loc_y = this.button1.Location.Y;
this.button1.Location = new Point(150,50);// Specify the button position
MessageBox.Show("Button1_X:"+ button1.Location.X + " Button1_Y:"+ button1.Location.Y);
}
Randomly update label position
private void label1_Click(object sender, EventArgs e)
{
Random random = new Random();
int n =random.Next(0,300); // Random range 0-300
this.label1.Location = new Point(n,n);// Randomly assigned location
}

checkBox Use
private void button1_Click(object sender, EventArgs e)
{
String str = " You bought :";
int sum = 0;
if (this.checkBox1.Checked == true)
{
str = str + " Apple ";
sum += 3;
}
if (this.checkBox2.Checked == true)
{
str = str + ", pitaya ";
sum += 5;
}
if (this.checkBox3.Checked == true)
{
str = str + ", watermelon ";
sum += 10;
}
MessageBox.Show(str + sum + " element ");
}
radiobutton Use
private void button2_Click(object sender, EventArgs e)
{
if (this.radioButton1.Checked == true)
Console.WriteLine(" male ");
else
Console.WriteLine(" Woman ");
}ComboBox Use
private void button1_Click(object sender, EventArgs e)
{
String str = this.comboBox1.SelectedItem.ToString();
Console.WriteLine(str);// Output the contents of the selected item
int a = this.comboBox1.SelectedIndex;
MessageBox.Show(this.comboBox1.Items[a].ToString());// Output the contents of the selected item
} 

SerialPort Use
send data
private void button1_Click(object sender, EventArgs e)
{
// send data
if(serialPort1.IsOpen == true)// Check if the port is open
{
String str = textBox1.Text; // Send the text content to the serial port
serialPort1.WriteLine(str);
}
}receive data

// When the serial port receives the data content , This event triggers and executes the following method
// This method is run by another sub thread of the system
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
String str = serialPort1.ReadLine(); // Read each row of data
serialPort1.DiscardInBuffer();// Get the data and clear the cache
textBox2.Text = str + textBox2.Text;
}
Specific serial communication articles :https://blog.csdn.net/m0_65592409/article/details/125213063?spm=1001.2014.3001.5501
PictureBox Use
Add image resources 
Import image

private int a = 0;
// Click on button Switch pictures
private void button1_Click(object sender, EventArgs e)
{
if(a == 0)
{
this.pictureBox1.Image = global::WinForms_image.Properties.Resources.p2;
a = 1;
}
else if(a == 1)
{
this.pictureBox1.Image = global::WinForms_image.Properties.Resources.p3;
a=2;
}
else if(a ==2)
{
this.pictureBox1.Image = global::WinForms_image.Properties.Resources.p1;
a = 0;
}
} 

边栏推荐
- Unity UGUI不同的UI面板或者UI之间如何进行坐标匹配和变换
- C语言数组专题训练
- Concurrent programming - deadlock troubleshooting and handling
- SD_CMD_RECEIVE_SHIFT_REGISTER
- Energy conservation and creating energy gap
- ROS2——常用命令行(四)
- Ros2 - workspace (V)
- Log4qt usage of logbase in QT project
- [software testing] 03 -- overview of software testing
- Edge calculation data sorting
猜你喜欢

Volcano resource reservation feature

ROS2——node节点(七)

Use the Paping tool to detect TCP port connectivity

Marvell 88e1515 PHY loopback mode test

PHY drive commissioning - phy controller drive (II)
![[MySQL 8.0 does not support capitalization of table names - corresponding scheme]](/img/ea/a1e0722c43f56aff3e79f95c99ba8a.png)
[MySQL 8.0 does not support capitalization of table names - corresponding scheme]

inux摄像头(mipi接口)简要说明

M2DGR 多源多场景 地面机器人SLAM数据集

.net core踩坑实践

Ros2 - install ros2 (III)
随机推荐
Marvell 88e1515 PHY loopback mode test
Marvell 88E1515 PHY loopback模式测试
C#学习笔记
[untitled]
namespace
Cookie、Session、JWT、token四者间的区别与联系
mysql设置触发器问题
docker安装mysql并使用navicat连接
现在有html文件,和用vs制作的mvc(连接了数据库),怎么两个相连?
window navicat连接阿里云服务器mysql步骤及常见问题
kata container
Ros2 - ros2 vs. ros1 (II)
An article was opened to test the real situation of outsourcing companies
C语言数组专题训练
PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)
testing framework
【软件测试】03 -- 软件测试概述
iNFTnews | 喝茶送虚拟股票?浅析奈雪的茶“发币”
Orin 安装CUDA环境
Executealways of unity is replacing executeineditmode