C# 工作笔记
1.获得登陆人id:
AppCommon.LoginUser().userId
2.弹框确认操作
if (MessageBox.Show("确认删除吗?", "注意",MessageBoxButton.YesNo, MessageBoxImage.Question) ==MessageBoxResult.Yes)
{
MessageBox.Show("删除成功!");
}
3.C#下拉列表默认选中特定行
4.StringBuilder,需要引入using System.Text(第一个参数是初始值,第二个参数是初始长度,默认需要设置相对准确1长度,最大长度为一个int,但是内存有时会溢出)
5.c#生成一定范围得数字
6.C#3.0新特性
7.c#的可空类型
8.C#四舍五入
9.C#的进度条控件
代码1:
<dxdo:LayoutControlItem>
<StackPanel Margin="0,10,0,5" Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Left" Width="1000" >
<Label Content="进度条:" Margin="10,20,0,0"/>
<ProgressBar x:Name="bar" Width="200" Height="20"/>
</StackPanel>
</dxdo:LayoutControlItem>
代码2:
private void queryBtn_Click(object sender, RoutedEventArgs e)
{
int count = 0;
System.Timers.Timer t = new System.Timers.Timer(200);//实例化Timer类,设置间隔时间为1000毫秒 就是1秒;
t.Elapsed += new System.Timers.ElapsedEventHandler((object source, System.Timers.ElapsedEventArgs e1) =>
{
//创建线程
Thread tast = new Thread(o =>
{
//int complete_nums = TestTask();
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
//跨线程修改UI 要使用Dispatcher 让这个操作委托给UI线程来完成
if (this.bar.Value == 100)
{
t.Enabled = false;
}
count++;
this.bar.Value = count;
}
));
})
{
IsBackground = true // 如果此线程为或将成为后台线程,则为 true;否则为 false。
};
tast.Start();
});
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
}
10.C#字符串拼接
输出:this is 23.46
11.指定特定列的背景色
(1)初始化时先定义
this.grid.CellBackgroundFunction = _ItemBrushCreate;
(2)定义方法
Public Brush _ItemBrushCreate(Object value, GridColumn fieldName)
{
if (value == null)
{
return null;
}
if (fieldName.FieldName.Equals("[realseorder]"))
{
return Brushes.Yellow;
}
else if (fieldName.FieldName.Equals("[flag1]"))
{
return Brushes.Yellow;
}
else if (fieldName.FieldName.Equals("[flag2]"))
{
return Brushes.Yellow;
}
else
{
return null;
}}
12.对grid选中做判断
if (this.grid.SelectedItems == null || this.grid.SelectedItems.Count <= 0)
{
return;
}
13.获取当前年、月、日、时、分
this.tbYear.Text = DateTime.Now.Year.ToString();
his.tbMonth.Text = DateTime.Now.Month.ToString();
this.tbDate.Text = DateTime.Now.Day.ToString();
this.tbHour.Text = DateTime.Now.Hour.ToString();
this.tbMinute.Text = DateTime.Now.Minute.ToString();
14.获取屏幕分辨率
//屏幕分辨率
int SH = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
int SW = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
//根据分辨率设置字体大小等设置
if (SW * SH == 800 * 600){
fontSize1 = 20;
fontSize2 = 80;
btnSize = 100;
barcodeHeight = 30;
weightHeight = 100;
}else if (SW * SH == 1024 * 768){
}else if (SW * SH == 1920 * 1080) {
}
15.前端XAML写C#代码
16.前端XAML使用静态资源