C#画图的一个问题 我想用C#在picturebox内画图,发现失败。就是直线画在picturebox外的部分能正常显示,而在picturebox内的部分被遮住。我的picturebox背景色必须是白色,不能改。请问如何解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace draw1{ public partial class Form1 : Form { bool bDraw; public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); PointF startPointF=new PointF(20,50); PointF endPointF=new PointF(300,50); if (bDraw) { Graphics g = e.Graphics; Pen p = new Pen(Color.Blue, 2); g.DrawLine(p, startPointF, endPointF); g.Dispose(); } } private void btnDraw_Click(object sender, EventArgs e) { this.Invalidate(); bDraw = true; } private void Form1_Load(object sender, EventArgs e) { } }}namespace draw1{ partial class Form1 { /// <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.btnDraw = new System.Windows.Forms.Button(); this.pbImg = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pbImg)).BeginInit(); this.SuspendLayout(); // // btnDraw // this.btnDraw.Location = new System.Drawing.Point(192, 260); this.btnDraw.Name = "btnDraw"; this.btnDraw.Size = new System.Drawing.Size(79, 26); this.btnDraw.TabIndex = 0; this.btnDraw.Text = "Draw"; this.btnDraw.UseVisualStyleBackColor = true; this.btnDraw.Click += new System.EventHandler(this.btnDraw_Click); // // pbImg // this.pbImg.BackColor = System.Drawing.Color.White; this.pbImg.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.pbImg.Location = new System.Drawing.Point(112, 12); this.pbImg.Name = "pbImg"; this.pbImg.Size = new System.Drawing.Size(363, 215); this.pbImg.TabIndex = 1; this.pbImg.TabStop = false; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(511, 316); this.Controls.Add(this.pbImg); this.Controls.Add(this.btnDraw); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pbImg)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button btnDraw; private System.Windows.Forms.PictureBox pbImg; }} treeview 如何显示出哪个节点当前是选中状态呢? 操作CSV文件的最佳方式,大家认为是用文件流好呢,还是用的OleDb方式好点 如何把NumbericUpDown 放入DataGridView中 winform 怎么实现在上传时可以一次选择多文件? 请教:DataTable数据如何序列化成XML文件 请问如何在C#中实现数据的批量存储,如下所示.......... zedgraph x轴与X2轴 的刻度如何可以做成一样 问------请答? 好心人能帮我看一下这个程序吗? 中文版的是否缺少应当有的函数 鼠标移动,获得当前树节点 C# 调用win32dll 高手请进 高分 在线等
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace draw1
{
public partial class Form1 : Form
{
bool bDraw;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
PointF startPointF=new PointF(20,50);
PointF endPointF=new PointF(300,50);
if (bDraw)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Blue, 2);
g.DrawLine(p, startPointF, endPointF);
g.Dispose();
}
}
private void btnDraw_Click(object sender, EventArgs e)
{
this.Invalidate();
bDraw = true;
}
private void Form1_Load(object sender, EventArgs e)
{ }
}
}
namespace draw1
{
partial class Form1
{
/// <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.btnDraw = new System.Windows.Forms.Button();
this.pbImg = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pbImg)).BeginInit();
this.SuspendLayout();
//
// btnDraw
//
this.btnDraw.Location = new System.Drawing.Point(192, 260);
this.btnDraw.Name = "btnDraw";
this.btnDraw.Size = new System.Drawing.Size(79, 26);
this.btnDraw.TabIndex = 0;
this.btnDraw.Text = "Draw";
this.btnDraw.UseVisualStyleBackColor = true;
this.btnDraw.Click += new System.EventHandler(this.btnDraw_Click);
//
// pbImg
//
this.pbImg.BackColor = System.Drawing.Color.White;
this.pbImg.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pbImg.Location = new System.Drawing.Point(112, 12);
this.pbImg.Name = "pbImg";
this.pbImg.Size = new System.Drawing.Size(363, 215);
this.pbImg.TabIndex = 1;
this.pbImg.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(511, 316);
this.Controls.Add(this.pbImg);
this.Controls.Add(this.btnDraw);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pbImg)).EndInit();
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button btnDraw;
private System.Windows.Forms.PictureBox pbImg;
}
}