0
當我第一次打開我的Windows窗體應用程序時,某些按鈕無法正確呈現,當窗體稍微移動時,它們就會出現。Windows窗體應用程序啓動時空白按鈕
見下文。
拖動它們出現的形式後。
這是我的啓動代碼。
[STAThread]
static void Main()
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "Support_Desk_System", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
GC.KeepAlive(mutex);
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}
這不是一個大問題,只是很煩人,因爲我不知道爲什麼會發生。
這是表單代碼。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.status_CodesTableAdapter.Fill(this.supportDeskDataSet.Status_Codes);
this.systemsTableAdapter.Fill(this.supportDeskDataSet.Systems);
this.cases_Quick_ViewTableAdapter.Fill(this.supportDeskDataSet.Cases_Quick_View);
this.dataGridView1.DoubleBuffered(true);
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
foreach (DataGridViewRow Myrow in dataGridView1.Rows)
{
if (Myrow.Cells[7].Value.ToString() == "High")
{
Myrow.DefaultCellStyle.BackColor = Color.Red;
}
else
{
Myrow.DefaultCellStyle.BackColor = Color.Green;
}
if(Myrow.Cells[2].Value.ToString() == "Back Burner")
{
Myrow.DefaultCellStyle.BackColor = Color.Gray;
Myrow.DefaultCellStyle.ForeColor = Color.White;
}
}
}
}
public static class DataGridViewExtensioncs
{
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
var dgvType = dgv.GetType();
var pi = dgvType.GetProperty("DoubleBuffered",
BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
我不認爲問題出現在那個代碼中......你在窗體的構造函數或Load事件中做什麼? – Pikoh
我同意@Pikoh。但是你的Main方法看起來很可疑。你確定,具有SetForegroundWindow的分支是正確的嗎? – TcKs
我不認爲它是@TcKs,它應該像'if(Process.GetProcessesByName(current.ProcessName).Any()){SetForegroundWindow(process.MainWindowHandle); '。但它與問題無關:) – Pikoh