开发环境:
1、操作系统:windows 专业版
2、开发软件:visual studio 系列,2005、2008、2010、1013及2017或更高版本
问题汇总:
1、窗体大小固定
在2010以前版本设置 窗体属性 的 FormBorderStyle 为 FixedSingle 或 fixed3D,MaximizeBox 设为 true 即可,几乎没什么问题,但在之后再加之所使用的笔记本等高分辨率屏幕的计算机开始,这两项好像不起作用了,这里提供个小技巧可以轻松解决,就是:
步骤一:设置以上两个属性
步骤二:关闭开发软件
步骤三:设置 系统的显示模式 显示设置 -> 缩放与布局(100%)
步骤四:开启开发软件 ,进入开发应用
步骤五:再次设置 系统的显示模式 显示设置 -> 缩放与布局(150%(推荐)),这里不同分辨率下,推荐的百分比不同
步骤六:再次回到应用,启动运行,即可看到效果
2、程序随系统启动而启动
附代码:
在启动窗体的Form_load 中加入以下代码即可:
try
{
if (isAuto == true)
{
RegistryKey R_local = Registry.CurrentUser;//RegistryKey R_local = Registry.CurrentUser;
RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
R_run.SetValue("FaceData", Application.ExecutablePath);
R_run.Close();
R_local.Close();
}
else
{
RegistryKey R_local = Registry.CurrentUser;//RegistryKey R_local = Registry.CurrentUser;
RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
R_run.DeleteValue("FaceData", false);
R_run.Close();
R_local.Close();
}
}
catch (Exception)
{
if (showinfo)
MessageBox.Show("您需要管理员权限修改", "提示");
}
3、某应用只允许运行一个
附代码
在应用下的Program.cs 文件中,加入如下代码:
static void Main()
{
Process[] processes = Process.GetProcesses();
Process currentProcess = Process.GetCurrentProcess();
bool processExist = false;
foreach (Process p in processes)
{
if (p.ProcessName == currentProcess.ProcessName && p.Id != currentProcess.Id)
{
processExist = true;
}
}
if (processExist)
{
MessageBox.Show("程序已运行,不能再次打开!");
Environment.Exit(1);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SourceSelect());
}
}
以上解决方案也参考了爱分享网友的,汇总分享给大家