English 中文(简体)
显示温形的影像和淋浴方法
原标题:Ambiguous Method of Show and ShowDialog For Displaying Winform

I am struggling between Show and ShowDialog method of Showing/Display of Windows Forms. I generally use the show method instead of the ShowDialog method. And the ShowDialog method is used when I don’t want to show the forms at ALT+TAB ToolWindow.

<代码>ShowDialog 方法显示modeldow form,与正常窗口表相比,准入受到限制。 模型窗口表没有获得控制的价值和已经通过正常窗口表格的标本。 因此,我们必须每次或每次都提供新形式的新的价值,而这种新形式正像现在这样。

//Purchase_Entry having a public method which is calling from form30 as under:

public partial class purchase_Entry : Form
{
    public purchase_Entry()
    {
        InitializeComponent();
    }

    public void Purchase_Binding()
    {
        mydgv.Location = new Point(0, 110);
        mydgv.RowHeadersVisible = false;
        mydgv.Width = panel2.Width;
        mydgv.Height = panel2.Height - 220;
        mydgv.TabIndex = 4;

        string connstr = "server=.;initial catalog=maa;uid=mah;pwd=mah";
        SqlConnection con = new SqlConnection(connstr);
        con.Open();

        string sql = @"select billno,date=convert(varchar,date,103),ledgeraccount,totcts,rround,grosspurchase,taxes,taxamt,totdb,narrat" +
                     " from depurchasea where companyID=@companyID" +
                     " and transID=@transID" +
                     " group by billno,date,ledgeraccount,totcts,rround,grosspurchase,taxes,taxamt,totdb,narrat" +
                     " order by date,billno";

        SqlCommand cmd = new SqlCommand(sql, con);
        cmd.Parameters.AddWithValue("companyID", label6.Text);
        cmd.Parameters.AddWithValue("transID", textBox5.Text);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            textBox2.Text       = Convert.ToString(ds.Tables[0].Rows[i]["billno"]);
            maskedTextBox1.Text = Convert.ToString(ds.Tables[0].Rows[i]["date"]);
            textBox1.Text       = Convert.ToString(ds.Tables[0].Rows[i]["ledgeraccount"]);
            textBox9.Text       = Convert.ToString(ds.Tables[0].Rows[i]["totcts"]);
            textBox7.Text       = Convert.ToString(ds.Tables[0].Rows[i]["rround"]);
            textBox13.Text      = Convert.ToString(ds.Tables[0].Rows[i]["grosspurchase"]);
            comboBox1.Text      = Convert.ToString(ds.Tables[0].Rows[i]["taxes"]);
            textBox8.Text       = Convert.ToString(ds.Tables[0].Rows[i]["taxamt"]);
            textBox6.Text       = Convert.ToString(ds.Tables[0].Rows[i]["totdb"]);
            textBox3.Text       = Convert.ToString(ds.Tables[0].Rows[i]["narrat"]);
        }

        //mydgv.Columns.Clear();

        string mysql = "select srno,particulars,carats,rate,debit from depurchasea" +
                     " where companyID=@companyID" +
                     " and transID=@transID";
        SqlCommand mycmd = new SqlCommand(mysql, con);
        mycmd.Parameters.AddWithValue("companyID", label6.Text);
        mycmd.Parameters.AddWithValue("transID", textBox5.Text);
        SqlDataAdapter mydap = new SqlDataAdapter(mycmd);
        DataSet myds = new DataSet();
        mydap.Fill(myds);
        mybinding = new BindingSource();
        mybinding.DataSource = myds;
        mybinding.DataMember = myds.Tables[0].TableName;
        mydgv.DataSource = mybinding;

        mydgv.Columns[0].HeaderText = "Sr.No.";
        mydgv.Columns[1].HeaderText = "Particulars";
        mydgv.Columns[2].HeaderText = "Carats";
        mydgv.Columns[3].HeaderText = "Rate";
        mydgv.Columns[4].HeaderText = "Amount";

        mydgv.Columns[0].Width = 50;
        mydgv.Columns[1].Width = 500;
        mydgv.Columns[4].Width = 100;
        mydgv.Columns[2].Width = 100;
        mydgv.Columns[3].Width = 100;

        mydgv.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
        mydgv.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
        mydgv.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
        mydgv.Columns[2].DefaultCellStyle.Format = "f2";
        mydgv.Columns[3].DefaultCellStyle.Format = "f2";
        mydgv.Columns[4].DefaultCellStyle.Format = "f2";
        mydgv.Columns[4].ReadOnly = true;

        int dgvsize = mydgv.Width / 17;
        mydgv.Columns[0].Width = dgvsize;
        mydgv.Columns[1].Width = dgvsize * 10;
        mydgv.Columns[2].Width = dgvsize * 2;
        mydgv.Columns[3].Width = dgvsize * 2;
        mydgv.Columns[4].Width = dgvsize * 2;
        mydgv.Refresh();

        if (textBox13.Text != "")
        {
            decimal res = Convert.ToDecimal(textBox13.Text);
            textBox13.Text = res.ToString("f2");
        }
    }

public partial class Form30 : Form
{
    public Form30()
    {
        InitializeComponent();
    }

    private void listView1_KeyPress(object sender, KeyPressEventArgs e)
    {


        else if (textBox2.Text == "Purchase")
        {
             purchase_Entry pc = new purchase_Entry();
             pc.lbl6.Text  = pp.Form1.IDD.Text; //companyID
             pc.Purchase_Binding() //Calling public method of purchase_entry Class
             pc.ShowDialog(this);
             pc.textboxKeypress += new purchase_Entry.Action(pc_textboxKeypress);
             pc.purkeydown += new purchase_Entry.Action(pc_purkeydown);

         }
     }

电话Purchase_Bled( >方法,purchase_Entry/strong> <<>Show(>)方法的表格运行良好,但如果在<>ShowDialog()方法上使用同一方法,则该表格将显示记录,但控制的统一也发生了变化。 这意味着,我不得不在<>ShowDialog()方法上公布每个控制规模、高度、宽度和公司ID的新价值。

If so, then it will donkey works for me, because I have to redesign purchase_Entry on the ShowDialog() method.

What is the best way?. If I deal with the Show() method then the form will show at ALT+TAB ToolWindow, and I don t want to allow to show it at ALT+TAB ToolWindow. That s why I used the ShowDialog() method which will show as a model window form and will not be displaying at ALT+TAB ToolWindow.

如果我使用<条码>ShowDialog()方法,那么我必须准备将其重新设计为“ don”。 难道没有吗?

问题回答

更改电话顺序。

private void button1_Click(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    f2.moto();
    f2.ShowDialog();
}

你在使用淋巴格时看不出本金呼吁的效果,其原因是,在表格关闭之前,显示原封不动,也就是说,在表格关闭之前,不会打上本金。

我希望这可能有助于你们。

这是你的违约构造者,其投入比投入多。

public Form2()
{
   InitializeComponent();
}

public Form2(int id)
{
    InitializeComponent();
    if(id == 101)
        textBox1.Text = "MAHESH";
}

public Form2(string name)
{
    InitializeComponent();    
    textBox1.Text = name;
}

Make the call as you require and pass in the value, you can encapsulate further processing in different methods and make the call.

新表格的编号只能在<条码>ShowDialog(后执行。

表格显示模式。 这意味着代码表。 在表格开放时,表演永远不会执行。

如果你的方法取决于国际发展法,你必须先把ID > 摆在之前,请打电话f2.moto(例如,在显示前)。

public partial class Form2 : Form
{
    public Form2(int id)
    {
        InitializeComponent();
        label1.Text = id.ToString();
    }

    public void moto()
    {
        textBox1.Text = "MAHESH";
    }
}

private void button1_Click(object sender, EventArgs e)
{
    Form2 f2 = new Form2(101);
    f2.moto();
    f2.ShowDialog();
}

EDIT:

如果你不使用微粒化构造,那么在打电话前,你还必须先验。

Use the public property Id in the Form2 class:

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    public void moto()
    {
        textBox1.Text = "MAHESH";
    }

    public int Id
    {
       set {label1.Text = value.ToString();}
    }
}

private void button1_Click(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    f2.Id = 101;
    f2.moto();
    f2.ShowDialog();
}




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签