关于C# 自定义控件库中如何绘图的问题!

来源:百度知道 编辑:UC知道 时间:2024/05/18 11:01:01
我现在想用vs2005的自定义控件库来画一个柱状图,以后可以生成.dll文件可以在别人的项目中直接引用,但是却发现在用户控件测试容器的预览中无法显示所画的图,不知什么原因,因为我在windows应用程序的窗体中实现过,但在自定义控件库中无法实现,请高手指点!!!比如下面的代码应该画一条直线可是无法显示,代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace testGraphics
{
public partial class UserControl1 : UserControl
{
private Graphics g;
public UserControl1()
{
InitializeComponent();
g = this.CreateGraphics();
Pen bluePen = new Pen(Color.Blue);
g.DrawLine(bluePen, 50, 50, 50, 100);
}

private void pictureBox1_Click(object sender, EventArgs e)
{

}

private void UserControl1_Load(object sender, EventArgs e)

public partial class UserControl1 : UserControl
{
private Graphics g;
public UserControl1()
{
InitializeComponent();

}

private void UserControl1_Paint(object sender, PaintEventArgs e)
{
g = this.CreateGraphics();
Pen bluePen = new Pen(Color.Blue);
g.DrawLine(bluePen, 50, 50, 50, 100);
}

}