c#开发windows应用程序几个小技巧

最近,我在用.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卡等,等完成了再给大家共享
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值