C# 括号折叠
VS2017 选项 - 文本编辑器 - C# - 高级 - 大纲 - 勾选 “显示代码级别构造的大纲”,其他版本安装扩展 outline , 工具-扩展和更新-联机-搜索 outline 安装即可
2020-06-17
当C# textbox 开启多行带滚动条时, 默认显示最上面的,有时候这样不能满足我们的应用场景,需要显示最新的数据时,需要显示最下面的数据。 我在网上找到三种方法,第一种效果最理想, 二三中效果几乎一样,不太理想,最要是刷新会闪烁,非常不爽
方法1
textBox_recive.AppendText(str);
方法二
textBox_recive.SelectionStart = textBox_recive.Text.Length;
textBox_recive.ScrollToCaret();
方法三
this.textBox_recive.Focus();//获取焦点
this.textBox_recive.Select(this.textBox_recive.TextLength, 0);//光标定位到文本最后
this.textBox_recive.ScrollToCaret();//滚动到光标处
tabControl 选中标签
选项卡切换触发的是tabcontrol控件的SelectedIndexChanged事件。
当tabcontrol控件的任何一个tabpage被点击或选择,即发生SelectedIndexChanged事件事件。
代码如下:
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (tabControl1.SelectedIndex == 0)//也可以判断tabControl1.SelectedTab.Text的值
{
//执行相应的操作
}else if(tabControl1.SelectedIndex == 1)
{
//执行相应的操作
}
}
C#直接打开计算器或记事本
private void gvButton1_Click(object sender, EventArgs e)
{
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
System.Diagnostics.Process proc = new System.Diagnostics.Process();
//设置外部程序名(记事本用 notepad.exe 计算器用 calc.exe)
info.FileName = "calc.exe";
//设置外部程序的启动参数
info.Arguments = "";
//设置外部程序工作目录为c:\windows
info.WorkingDirectory = "c:/windows/";
try
{
//
//启动外部程序
//
proc = System.Diagnostics.Process.Start(info);
}
catch
{
MessageBox.Show("系统找不到指定的程序文件", "错误提示!");
return;
}
}
自动加载已有串口
1)using System.IO.Ports;//确保包含
2)
private void comboBox_Uart_Com_Click(object sender, EventArgs e)
{
comboBox_Uart_Com.Items.Clear();//清除控件中的信息
string[] sps = SerialPort.GetPortNames();//将数据 放入对应缓存
comboBox_Uart_Com.Items.AddRange(sps);//加载到控件中
}
格式化数据显示
text_1_14.Text = string.Format("{0:f1}", Data_U16[13] / 10.0);
窗体属性设置
1 关闭最大化 最小化
this.MaximizeBox =false;
this.MinimizeBox =false;
2. 设置FormBorderStyle 窗体的边框样式
//默认可调整大小的边框模式
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
//固定的三维边框 固定窗体大小
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
3.设置窗体出现的位置
//出现在屏幕正中央
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
label对齐
饼状图宽度