有静态方法show并能返回结果,谢谢了
解决方案 »
- ZIP格式压缩文件时SetLevel()设置多少?
- 定义与类名称相同的函数为什么不需要返回类型?
- TextBox中如何写代码去创建新窗体
- 统计查询问题treeview的表结构
- 求教如何输出字符串中转义字符的字面值的问题
- 公司网站程序打算升级C#撰写的,当初是Vs2003开发的,现在打算用Vs2008,请教一下几个问题,请高手指教?
- asp.net中怎么去掉TreeView的闪烁
- 弱弱的问一下EventLog类生成的log放在哪了??
- CSDN上的朋友给女朋友送花的我打五折...........
- 求思路:如何写一个C#程序去控制另外一个.exe程序?
- 遇到了一个问题???请大家帮帮忙???
- 异常“System.StackflowException "是什么意思
static bool show()
{
this.DhowDillogue();
return v;
}
先建一个form,假设叫Form2,有标签有确定像messageBox一样;把构造函数私有
class Form2{
private static Form2 _form;
//....
label caption;
private string Caption{
get{return caption.text;}
set{caption.text = value;}
}
private Form2(){
//initials here...
}static public Show(string text){
if(_form == null){
_form = new Form2();
} _form.Caption = text;
_form.ShowDialog();
}
}
好像行不通吧,静态方法中能调用this.ShowDialog吧, this也可以说类的实例吧
这种方法好像也行不通,你试过了吗
public static int showsum(int a,int b){
return a+b;
}
}调用:
MessageBox.Show(jeky.showsum(3,6).ToString());
{
public myclass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static bool show(string showString,string caption)
{
DialogResult a=MessageBox.Show(showString,caption,MessageBoxButtons.OKCancel);
if (a==DialogResult.OK)
return true;
else return false;
}
这只是一个简单的例子,给你提供了一种思想。
如果点“确定”会返回 true 然后......
如果要向messagebox那样功能强大,需要做很多工作。
}
private static Font font = null;public static DialogResult Show(string msg, string caption, MessageBoxButtons buttons)
{
message = msg; MsgBox box = new MsgBox(); // 定义并实例化 MsgBox 对象
font = box.Font; // 返回窗口的字体
box.Text = caption; // Text 属性设置
box.Icon = SystemIcons.Application;
box.Size = new Size(320, 150); // 窗口大小 // 判断加载什么样的按钮
switch(buttons)
{
case MessageBoxButtons.OK : // 判断加载什么样的按钮
// 动态添加按钮
Button b = new Button();
b.Text = "确定(&O)";
b.Size = new Size(74,23);
b.Location = new Point(
(box.Width - b.Width) / 2,
box.ClientSize.Height - (b.Height + 20));
b.DialogResult = DialogResult.OK; // 设置按钮的 DialogResult
b.Select();
box.Controls.Add(b);
box.AcceptButton = b; break;
case MessageBoxButtons.OKCancel :
break;
} // 关联窗口的绘制事件
box.Paint += new PaintEventHandler(box_Paint); return box.ShowDialog(); // 显示对话框
}private static void box_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// 在这个事件里面可以利用 sender 对象返回 MsgBox MsgBox box = (MsgBox)sender; Graphics g = e.Graphics; // 返回 e.Graphics 对象 // 通过 g.MeasureString() 方法 返回字符串的 Size 调整窗口的大小
// SizeF sf = g.MeasureString(message, font);
g.DrawIcon(System.Drawing.SystemIcons.Exclamation, 10 , 10);
g.DrawString(message, font, new SolidBrush(SystemColors.WindowText), 50.0f, 20.0f);
}然后在另一窗口 Form1 的 Click 事件中加入:
this.Text = MsgBox.Show("我的消息框", "消息 MessageBox", MessageBoxButtons.OK).ToString();