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”。 难道没有吗?