日期:2014-05-20  浏览次数:20782 次

Graphics 问题,在线等~~
一个简单的问题
我现在用g.DrawLine()的方法画一条线
但如果在一条线的中间有个控件的话则控件这段线会被遮盖掉,如何可以使控件这段线不被遮盖呢?

------解决方案--------------------
API可以。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace 经典测试
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public class test
{
public int m_nX;
public static int y = 30;
static test()
{
y = 150;
}
public test()
{
m_nX = 8;
y = 72;
}
}
private void button1_Click(object sender, EventArgs e)
{
int x = test.y;
test d = new test();
int z = test.y;
}

[DllImport( "user32.dll ", EntryPoint = "GetWindowDC ")]
public static extern IntPtr GetWindowDC(IntPtr hwnd);
[DllImport( "user32.dll ", EntryPoint = "ReleaseDC ")]
public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
private void button2_Click(object sender, EventArgs e)
{

}

private void Form1_Paint(object sender, PaintEventArgs e)
{
IntPtr hDC = GetWindowDC(this.Handle);
using (Graphics g = Graphics.FromHdc(hDC))
{
g.DrawLine(Pens.Black, 0, 0, 150, 150);
}
ReleaseDC(this.Handle, hDC);
}
}
}