博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c#开发windows应用程序几个小技巧
阅读量:5277 次
发布时间:2019-06-14

本文共 2157 字,大约阅读时间需要 7 分钟。

最近,我在用.net做一个c/s的项目,把我做的情况给大家说说。
datagrid是用的c1控件的c1FlexGrid,功能很多。
c1FlexGrid1.jpg
自定义分组和outlook形式的列头拖拽。
textbox,combobox,checkbox是继承.net自带的控件,自己扩展的。
现在说一说碰到的几个问题,及解决方法:
1.一个应用程序只能被用户打开一次
None.gif
 Process mobj_pro 
=
Process.GetCurrentProcess();
None.gif            Process[] mobj_proList
=
Process.GetProcessesByName(mobj_pro.ProcessName);
None.gif            
if
(mobj_proList.Length
>
1
)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                MessageBox.Show(
"当前的应用程序已打开!""系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
InBlock.gif                
return;
ExpandedBlockEnd.gif            }
2.一个框架窗口下只打开一个子窗口
None.gif
CustomerAdd pobj_CustomerAdd;  
None.gif            Form pobj_CustomerAdd_Return
=
CheckIsExit(
"
CustomerAdd
"
);
None.gif            
if
(pobj_CustomerAdd_Return
==
null
)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                pobj_CustomerAdd
=new CustomerAdd();
InBlock.gif                OpenSheet(pobj_CustomerAdd);
ExpandedBlockEnd.gif            }
None.gif            
else
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                OpenSheet((CustomerAdd)pobj_CustomerAdd_Return);
ExpandedBlockEnd.gif            }
  
None.gif
void
 OpenSheet(Form pobj_form)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif
InBlock.gif            pobj_form.MdiParent
=this;
InBlock.gif            pobj_form.Show(); 
ExpandedBlockEnd.gif        }
None.gif
ExpandedBlockStart.gifContractedBlock.gif        
/**/
/// <summary>
InBlock.gif        
/// 判断窗口是否存在
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="ps_windowName">窗口的名称</param>
ExpandedBlockEnd.gif        
/// <returns>存在返回此窗口的实例 不存在返回null</returns>
None.gif
        Form CheckIsExit(
string
 ps_windowName)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif
{
InBlock.gif            
for(int i=0;i<this.MdiChildren.Length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(this.MdiChildren[i].Name==ps_windowName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return this.MdiChildren[i];
ExpandedSubBlockEnd.gif                }
ExpandedSubBlockEnd.gif            }
InBlock.gif            
return null;
ExpandedBlockEnd.gif        }
3.弹出式窗口显示渐变效果
在页面上添加一个timer控件fadeTimer,interval设为50
类的实例变量为
private m_showing=true;
在form_load中写:
None.gif
Opacity 
=
 
0.0
;
None.gif            Activate();
None.gif            Refresh();
None.gif            fadeTimer.Start();
None.gif            Refresh();    
在timer控件的Tick事件中写:
None.gif
if
 (m_showing)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                
double d = 1000.0 / fadeTimer.Interval / 100.0;
InBlock.gif                
if (Opacity + d >= 1.0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
= 1.0;
InBlock.gif                    fadeTimer.Stop();
ExpandedSubBlockEnd.gif                }
InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
+= d;
ExpandedSubBlockEnd.gif                }
ExpandedBlockEnd.gif            }
None.gif            
else
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif
{
InBlock.gif                
double d = 1000.0 / fadeTimer.Interval / 100.0;
InBlock.gif                
if (Opacity - d <= 0.0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
= 0.0;
InBlock.gif                    fadeTimer.Stop();
ExpandedSubBlockEnd.gif                }
InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Opacity 
-= d;
ExpandedSubBlockEnd.gif                }
ExpandedBlockEnd.gif            }
4.在控件textbox中实现按回车键相当于tab键的作用
None.gif
public
 
class
 OSTextBox:TextBox
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif
{
InBlock.gif        
public OSTextBox()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
ExpandedSubBlockEnd.gif        }
InBlock.gif
InBlock.gif        
bool mb_IsKeyEnter=true;
InBlock.gif
InBlock.gif        [
InBlock.gif        Category(
"Data"),
InBlock.gif        DefaultValue(
true),
InBlock.gif        MergableProperty(
false)
InBlock.gif        ]
InBlock.gif        
public bool IsKeyEnter
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return mb_IsKeyEnter;
ExpandedSubBlockEnd.gif            }
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                mb_IsKeyEnter
=value;
ExpandedSubBlockEnd.gif            }
ExpandedSubBlockEnd.gif        }
InBlock.gif
InBlock.gif        
protected override void OnKeyPress(KeyPressEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.OnKeyPress (e);
InBlock.gif            
if(mb_IsKeyEnter)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (e.KeyChar == (char)Keys.Enter)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    SendKeys.Send(
"{Tab}");
ExpandedSubBlockEnd.gif                }
ExpandedSubBlockEnd.gif            }
ExpandedSubBlockEnd.gif        }
InBlock.gif
ExpandedBlockEnd.gif    }
还有很多东西,正在研究中,比如发票套打在c/s中的实现,用.net读取IC卡等,等完成了再给大家共享

转载于:https://www.cnblogs.com/martinxj/archive/2004/07/23/26969.html

你可能感兴趣的文章
打飞机游戏【来源于Crossin的编程教室 http://chuansong.me/account/crossincode 】
查看>>
[LeetCode] Merge Intervals
查看>>
【翻译自mos文章】当点击完 finishbutton后,dbca 或者dbua hang住
查看>>
Linux编程简介——gcc
查看>>
2019年春季学期第四周作业
查看>>
MVC4.0 利用IActionFilter实现简单的后台操作日志功能
查看>>
rotate the clock
查看>>
bugku 变量
查看>>
数据库01 /Mysql初识以及基本命令操作
查看>>
数据库02 /MySQL基础数据类型以及多表之间建立联系
查看>>
Python并发编程04/多线程
查看>>
CF461B Appleman and Tree
查看>>
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>
CF1215E Marbles
查看>>
BZOJ2339 HNOI2011卡农(动态规划+组合数学)
查看>>
octave基本操作
查看>>
axure学习点
查看>>
WPF文本框只允许输入数字[转]
查看>>