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