Hola, aqui tengo un codigo que no se como hacer que funcione. Trato de crear
un objeto graphics llamado lienzo a partir de un objeto pictureBox1 y
acceder a el desde un metodo llamado Button1_Click.
El caso es que el objeto creado desde el constructor no es visible desde tal
metodo Button1_Click, lo he probado todo y estoy convencido de que es una
chorrada, entonces, ¿que hago mal? (o que no hago).
Gracias,
Eric
Aqui esta el codigo para los que me lean,
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace CallCenter
{
public class clsLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
public clsLogin()
{
InitializeComponent();
lienzo=new pictureBox1.CreateGraphics(); //
<- esta es la linea donde declaro
e inicializo el objeto
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.pictureBox1.BorderStyle System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(64, 80);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(280, 160);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.button1.Location = new System.Drawing.Point(304, 256);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 302);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.pictureBox1});
this.Name = "clsLogin";
this.Text = "Logon usuario";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new clsLogin());
}
private void button1_Click(object sender, System.EventArgs e)
{
Pen lapizRojo=new Pen(Color.Red);
lienzo.DrawLine(lapizRojo,0,0,100,100);
<- y aqui no la
ve
}
}
}
Leer las respuestas