目标:使用VS建立窗口程序,通过DX绘制窗口背景色。

 

1,安装DX(含有托管的版本)。

2,使用VS建立窗口程序。

3,引入托管DX环境。

DX之“HelloWord”

4,编写基础代码。全部在MainForm代码文件中。

原始代码:

DX之“HelloWord”

 

修改后代码

引入DX

DX之“HelloWord”

class MainForm : Form
{
   public MainForm()
   {
       InitializeComponent();
       this.InitialDX();
   }
 
   private Device device = null;
 
   private void InitialDX()
   {
       PresentParameters presentParams = new PresentParameters();
       presentParams.Windowed = true;
       presentParams.SwapEffect = SwapEffect.Discard;
 
       device = new Device(
           0,
           DeviceType.Hardware,
           this,
           CreateFlags.SoftwareVertexProcessing,
           presentParams);
   }
 
   protected override void OnPaint(PaintEventArgs e)
   {
       base.OnPaint(e);
       this.DrawDX();
   }
 
   private void DrawDX()
   {
       if (this.device == null)
           return;
 
       this.device.Clear(ClearFlags.Target,
           Color.AliceBlue,
           1f,
           0);
 
       this.device.BeginScene();
       //绘制DX图形
       this.device.EndScene();
 
       this.device.Present();//显示图形
   }
}

相关文章:

  • 2022-12-23
  • 2022-01-22
  • 2021-09-11
  • 2021-08-24
  • 2021-08-28
  • 2021-08-13
  • 2021-12-10
  • 2021-09-13
猜你喜欢
  • 2021-09-24
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案