Direct2D / GDI + and the slow drawing of Windows forms - what can I do?

I work a lot with Visual Studio 2008, .NET C # 2.0-3.5 and Windows Forms, and I, like many others, noticed that GDI + draws controls very slowly. Note that I do not deal with images (JPG, GIF, etc.). Images are only icons in certain places. These are actually Controls / Forms / etc, which are slowly drawn.

The problem is that you can see the controls looming, and it may take a few seconds for the seemingly easy set of controls. Those. his lag and horror.

I did tests where I just put a few shortcuts (40-50) on the form, pressing F5 to run, and wait for them to be drawn. Again, lagging and not a very pleasant experience.

So then there is WPF that can solve this problem, but we / we are not ready to switch to WPF. So I look at workarounds or fixes, and I came across Direct2D, and while reading these other libraries,

Put me a little puzzled, and so these questions:

1) First, I want a pretty simple and easy way to just replace GDI + with something with a faster and hardware accelerated approach. Can this be done without switching to WPF and without rewriting all my Windows Forms code?

Whenever I read something in Direct2D, I see long blocks of usually awful C ++ code, telling me how to manually write code for drawing. I do not want it.

2) While reading online, I came across SlimDX, but I can’t figure out how to use it (and I admit that I wasn’t very good at writing). Suppose I already have a GUI application (Windows Forms, standard C # code). Can I somehow use SlimDX (or something like that) to just “replace” GDI + with too much rewriting?

My problem is that I cannot find any examples or tell me if SlimDX, Direct2D or other similar things can be used in my already created Windows Forms software, and if possible, how to do it.

Hope Im not too fuzzy =)

== EDIT == 2010-09-22

:

UserControl, . , GroupControl , .Text- .

10 Label. , , , , , 500 . , , , 0 .

== EDIT 2 == 2010-09-22

. String Text- , , .

Im, DevExpress, LabelControls AutoSizeMode. "", , . , Label, AutoSize = true/false.

" ", - , .

+4
5

. 3D- CAD GDI + , , . -. - , .

. . , :)

+2

GDI , GDI+. 4-5 , GDI # - , . , BitBlt, , () . , JPEG, GDI, CxImage HBitmap, .

, GDI . DirectX , , .

+1

. , 2D- , 10 - 50 . , , direct2d Vista 2 . , :

http://www.tomshardware.com/news/msft-windows-xp-windows-7-market-share-win7,13876.html

38,5% Windows - XP 2011 . , , XP, ( , XP), :

, GDI + , , , . . , , Microsoft gui Windows7 GDI +:

http://www.windows7taskforce.com/view/3607

: "gdi + Windows 7".

+1

SlimDX #... 3D. 2D-, 2D-. SlimDX - DirectX. , DirectX. , , .

- , WPF, #, accellerated, . GDI/Winforms. , GDI +, ( , ..).

Edit:

. , . , , . , , .

public class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        // *** EDIT ***
        this.tabPage1.SuspendLayout();
        this.tabPage2.SuspendLayout();
        this.tabControl1.SuspendLayout();
        this.SuspendLayout();

        FillTab(tabPage1, Color.White);
        FillTab(tabPage2, Color.Yellow);

        // *** EDIT ***
        this.tabPage1.ResumeLayout(false);
        this.tabPage2.ResumeLayout(false);
        this.tabControl1.ResumeLayout(false);
        this.ResumeLayout(false);
    }

    private static void FillTab(TabPage tabPage, Color color)
    {
        for (int i = 0; i < 200; ++ i)
        {
            int left = (i % 5) * 320;
            int topOffset = (i / 5) * 23;
            tabPage.Controls.Add(new Label { Left = left, Top = topOffset, Width = 100, Text = "Label" });
            tabPage.Controls.Add(new TextBox() { BackColor = color, Left = left + 100, Top = topOffset, Width = 100, Text = tabPage.Text });
            tabPage.Controls.Add(new ComboBox { BackColor = color, Left = left + 200, Top = topOffset, Width = 100 });
        }

    }

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.tabControl1 = new System.Windows.Forms.TabControl();
        this.tabPage1 = new System.Windows.Forms.TabPage();
        this.tabPage2 = new System.Windows.Forms.TabPage();
        this.tabControl1.SuspendLayout();
        this.SuspendLayout();
        // 
        // tabControl1
        // 
        this.tabControl1.Controls.Add(this.tabPage1);
        this.tabControl1.Controls.Add(this.tabPage2);
        this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.tabControl1.Location = new System.Drawing.Point(0, 0);
        this.tabControl1.Name = "tabControl1";
        this.tabControl1.SelectedIndex = 0;
        this.tabControl1.Size = new System.Drawing.Size(292, 266);
        this.tabControl1.TabIndex = 0;
        // 
        // tabPage1
        // 
        this.tabPage1.Location = new System.Drawing.Point(4, 22);
        this.tabPage1.Name = "tabPage1";
        this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
        this.tabPage1.Size = new System.Drawing.Size(284, 240);
        this.tabPage1.TabIndex = 0;
        this.tabPage1.Text = "tabPage1";
        this.tabPage1.UseVisualStyleBackColor = true;
        // 
        // tabPage2
        // 
        this.tabPage2.Location = new System.Drawing.Point(4, 22);
        this.tabPage2.Name = "tabPage2";
        this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
        this.tabPage2.Size = new System.Drawing.Size(245, 217);
        this.tabPage2.TabIndex = 1;
        this.tabPage2.Text = "tabPage2";
        this.tabPage2.UseVisualStyleBackColor = true;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Controls.Add(this.tabControl1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.tabControl1.ResumeLayout(false);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.TabControl tabControl1;
    private System.Windows.Forms.TabPage tabPage1;
    private System.Windows.Forms.TabPage tabPage2;
}
0

You can try managed directx, but they no longer support it (switched to XNA). Honestly, if you don’t have a crappy computer or tons of controls, I don’t know why it will be so bad. If you are doing intense processor stuff in your main thread, move it to a separate thread. This is the only reason I can think that this will lead to such a lag.

0
source

All Articles