程序启动前的欢迎界面+设置 屏幕分辨率

//using System;
//
//namespace CNEE.IF.VCY
//{
// /// <summary>
// /// SetPCscreen 的摘要说明。
// /// </summary>
// public class SetPCscreen
// {
//  public SetPCscreen()
//  {
//   //
//   // TODO: 在此处添加构造函数逻辑
//   //
//  }
// }
//}

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
//using Sunisoft.IrisSkin;

namespace CNEE.IF.VCY  
 

 class ScreenMode :Form
   
 {
  #region
  enum DMDO { DEFAULT = 0, D90 = 1, D180 = 2, D270 = 3 }
   
  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
   struct DEVMODE
           
  {
   public  const int DM_BITSPERPEL       = 0x040000;
   public  const int DM_PELSWIDTH        = 0x080000;
   public  const int DM_PELSHEIGHT       = 0x100000;
   public  const int DM_DISPLAYFREQUENCY = 0x400000;
   private const int CCHDEVICENAME       = 32;
   private const int CCHFORMNAME         = 32;
       
   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
   public string dmDeviceName;
   public short  dmSpecVersion;
   public short  dmDriverVersion;
   public short  dmSize;
   public short  dmDriverExtra;
   public int    dmFields;
      
   public int    dmPositionX;
   public int    dmPositionY;
   public DMDO   dmDisplayOrientation;
   public int    dmDisplayFixedOutput;
       
   public short  dmColor;
   public short  dmDuplex;
   public short  dmYResolution;
   public short  dmTTOption;
   public short  dmCollate;
       
   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
   public string dmFormName;
   public short  dmLogPixels;
   public int    dmBitsPerPel;
   public int    dmPelsWidth;
   public int    dmPelsHeight;
   public int    dmDisplayFlags;
   public int    dmDisplayFrequency;
   public int    dmICMMethod;
   public int    dmICMIntent;
   public int    dmMediaType;
   public int    dmDitherType;
   public int    dmReserved1;
   public int    dmReserved2;
   public int    dmPanningWidth;
   public int    dmPanningHeight;
      
   public override string ToString()
                
   {
    return string.Format
     (
     "{0,4}×{1,-4} {2,2}Bits {3,3}Hz  {4}",
     dmPelsWidth,
     dmPelsHeight,
     dmBitsPerPel,
     dmDisplayFrequency,
     dmDeviceName
     );
   }
  }
 
  [DllImport("user32.dll", CharSet = CharSet.Auto)]
  static extern bool EnumDisplaySettings(int lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
  #endregion
  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ScreenMode));
   this.timer1 = new System.Windows.Forms.Timer(this.components);
   this.label1 = new System.Windows.Forms.Label();
   this.timer2 = new System.Windows.Forms.Timer(this.components);
   this.SuspendLayout();
   //
   // timer1
   //
   this.timer1.Interval = 6000;
   this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
   //
   // label1
   //
   this.label1.BackColor = System.Drawing.Color.LightGray;
   this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   this.label1.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
   this.label1.ForeColor = System.Drawing.Color.WhiteSmoke;
   this.label1.Location = new System.Drawing.Point(528, 392);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(96, 24);
   this.label1.TabIndex = 2;
   this.label1.Text = "CNEE-CY";
   //
   // timer2
   //
   this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
   //
   // ScreenMode
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
   this.ClientSize = new System.Drawing.Size(624, 416);
   this.Controls.Add(this.label1);
   this.ForeColor = System.Drawing.Color.IndianRed;
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
   this.MaximizeBox = false;
   this.MinimizeBox = false;
   this.Name = "ScreenMode";
   this.Opacity = 0.01;
   this.ShowInTaskbar = false;
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
   this.TopMost = true;
   this.Load += new System.EventHandler(this.ScreenMode_Load);
   this.ResumeLayout(false);

  }
  #region
  [DllImport("user32.dll", CharSet = CharSet.Auto)]
  static extern int ChangeDisplaySettings([In] ref DEVMODE lpDevMode, int dwFlags);

  private System.Windows.Forms.Timer timer1;
  private System.ComponentModel.IContainer components = null;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Timer timer2;
 
  ListBox lbxPels;
 
  // 构造函数
  public ScreenMode()
     
  {
   Text                   = "港口集装箱三维实训系统";
 
   lbxPels                = new ListBox();
   lbxPels.Visible=false;
   lbxPels.Parent         = this;
   lbxPels.Dock           = DockStyle.Fill;
   lbxPels.BeginUpdate();
   DEVMODE DevMode        = new DEVMODE();
   for (int i = 0; EnumDisplaySettings(0, i, ref DevMode); i++)
      
   {
    lbxPels.Items.Add(DevMode);
   }
   lbxPels.EndUpdate();
 
   Button btnSet          = new Button();
   btnSet.Visible=false;
   btnSet.Parent          = this;
   btnSet.Text            = "设置显示模式";
   btnSet.Dock            = DockStyle.Top;
   btnSet.Click          += new EventHandler(SetScrnMode);
 
   Button btnGet          = new Button();
   btnGet.Visible=false;
   btnGet.Parent          = this;
   btnGet.Text            = "当前显示属性";
   btnGet.Dock            = DockStyle.Top;
   btnGet.Click          += new EventHandler(GetScrnInfo);
   InitializeComponent();//初始化
   //
//   sk=new SkinEngine();
//   try
//   {
//    sk.SkinAllForm=true;
//    sk.BuiltIn=false;
//    sk.DisableTag=11;//同时把mianFrom的panel2的tag改为11生效
//    sk.SkinFile = Application.StartupPath + "//skin//MSN//MSN.ssk";
//    //sk.AddtionalBuiltInSkins();
//   }
//   catch
//   {
//    sk.Active=false;
//    sk.Dispose();
//       
//   }
  }
  void SetSceen(int i)
  {
   if(i==1)
   {
    //800x600 75hz,16Bits
    foreach(object sb in lbxPels.Items)
    {
     string s=sb.ToString();
     if(s.IndexOf("800")!=-1&&s.IndexOf("600")!=-1&&s.IndexOf("75")!=-1&&s.IndexOf("32Bits")!=-1)
     {
      DEVMODE DevMode = (DEVMODE)sb;
      ChangeDisplaySettings(ref DevMode, 0);
     }
    }
   }
   if(i==2)
   {
    //1024x768 75hz,16bits
    foreach(object sb in lbxPels.Items)
    {
     string s=sb.ToString();
     if(s.IndexOf("1024")!=-1&&s.IndexOf("768")!=-1&&s.IndexOf("75")!=-1&&s.IndexOf("32Bits")!=-1)
     {
      DEVMODE DevMode = (DEVMODE)sb;
      ChangeDisplaySettings(ref DevMode, 0);
     }
    }
   }
  }
  // 设置显示模式
  void SetScrnMode(object sender, EventArgs e)
    
  {
   if (lbxPels.SelectedItem != null)
       
   {
    DEVMODE DevMode = (DEVMODE)lbxPels.SelectedItem;
    ChangeDisplaySettings(ref DevMode, 0);
   }
  }
 
  // 当前显示属性
  void GetScrnInfo(object sender, EventArgs e)
    
  {
   Screen scrn = Screen.PrimaryScreen;
   MessageBox.Show(
    string.Format
    (
    "主设备: {1}{0}设备名: {2}{0}边 界: {3}{0}工作区: {4}",
    Environment.NewLine,
    scrn.Primary,
    scrn.DeviceName,
    scrn.Bounds,
    scrn.WorkingArea
    ),
    "当前显示属性",
    MessageBoxButtons.OK,
    MessageBoxIcon.Information
    );
  }
  #endregion
  // 程序入口
  static void sceenMain()
   
  {
   Application.Run(new ScreenMode());
  }
//  public static SkinEngine sk;
  private void ScreenMode_Load(object sender, System.EventArgs e)
  {
//   Random rn=new Random();
//   int i=rn.Next(3);
//   while(i<1||i>2)
//   {
//    i=rn.Next(3);
//   }
   try
   {
    
    SetSceen(2);
    timer1.Start();
    timer2.Start();
   }
   catch
   {
    timer1.Start();
    timer2.Start();
   }
  }

  private void timer1_Tick(object sender, System.EventArgs e)
  {
   this.Close();
  }

  private void timer2_Tick(object sender, System.EventArgs e)
  {
   if(this.Opacity<=0.8f)
   this.Opacity+=0.05f;
  }
 }
// void changeres(int chmode) {}
//
// long retval = 0;
//
// form1 t = new form1();
//
// devmode dm = new devmode();
//
// dm.dmsize = (short)marshal.sizeof(typeof(devmode));
//
// if (chmode == 1)
//
//{
//
// dm.dmpelswidth = 1600;
//
// dm.dmpelsheight = 1024;
//
// dm.dmdisplayfrequency = 85;
//
//}
//
// else if (chmode == 2)
//
//{
//
// dm.dmpelswidth = 1024;
//
// dm.dmpelsheight = 768;
//
// dm.dmdisplayfrequency = 85;
//
//}
//
// dm.dmfields = devmode.dm_pelswidth | devmode.dm_pelsheight | devmode.dm_displayfrequency;
//
// retval = changedisplaysettings(ref dm, 0);
//
//}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rains卍Soft

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值