博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
架构师
查看>>
UIDatePicker自定义背景
查看>>
JS 日期比较
查看>>
ORM的单表操作
查看>>
Radar Installation
查看>>
Read and write SD cards in a raw way with dd
查看>>
Android Activity生命周期举例说明(图文)
查看>>
deinstall oracle 11g on linux
查看>>
4. Median of Two Sorted Arrays *HARD* -- 查找两个排序数组的中位数(寻找两个排序数组中第k大的数)...
查看>>
Windows安装MySQL5.7.17
查看>>
JS面向对象与原型
查看>>
编程之美-2.18-数组分割
查看>>
BZOJ4860 Beijing2017树的难题(点分治+单调队列)
查看>>
BZOJ5372 PKUSC2018神仙的游戏(NTT)
查看>>
删除mac 自带的python2.7后,XCODE运行失败,如下图,重装python2.7后解决,以后不敢乱动了。...
查看>>
首次开通blog,以后会慢慢把oneNote和印象笔记的笔记转过来
查看>>
SDN第一次作业
查看>>
6410开发板串口连接配置及裸机程序烧写步骤
查看>>
JsonCpp中文unicode编码问题
查看>>
C++并发编程 thread
查看>>