MainForm - 2 buttons and 1 InformationPanel. InformationPanel extends AbstractSuperPanel which extends Panel.
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
void Button2Click(object sender, EventArgs e)
{
}
void BackgroundWorker1DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
informationPanel1.StartWorking();
}
}
AbstractPanel. This just sets up the class as it should look in the main form. When extended the child class just implements it's own controls.
public Label PanelLabel = new Label();
public AbstractPanel()
{
PanelLabel.Location = new Point(0,0);
PanelLabel.Font = new Font("Arial", 10F, FontStyle.Bold, GraphicsUnit.Point, 0x00);
this.SuspendLayout();
this.BorderStyle = BorderStyle.FixedSingle;
this.BackColor = SystemColors.Control;
this.Font = new Font("Arial", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
this.Size = new Size(200, 200);
this.Controls.Add(PanelLabel);
InitializeComponent();
this.ResumeLayout(false);
}
public abstract void InitializeComponent();
public abstract void StartWorking();
}
And now my InformationPanel.
public class InformationPanel : AbstractPanel
{
private Label WorkLabel = new Label();
public InformationPanel()
{
}
public override void StartWorking()
{
AsyncOperation operation = AsyncOperationManager.CreateOperation(null);
ThreadPool.QueueUserWorkItem(new WaitCallback(StartLabels));
}
private void StartLabels(object stateInfo)
{
Thread.Sleep(1000);
WorkLabel.Text = "Finished";
}
public override void InitializeComponent()
{
PanelLabel.Text = "Information";
WorkLabel.Font = base.Font;
WorkLabel.Location = new Point(2,22);
this.Controls.Add(WorkLabel);
}
}
As you can see the concept is easy. I just want to populate the child panels labels with the StartWorking() method. In my main project I have 12 similar panels that will eventually extend AbstractPanel as it does here so that I can loop through my controls in my main form from the background worker and tell it to work. I have it working somewhat in my main program, but I'm doing it a little differently. I also haven't implemented Abstract panel to all my panels yet. Maybe I was doing it right in this version, I just don't know. All I know is it that it works. Keep in mind that none of the panels talk to each other and can be thought of almost as 12 individual programs. Here is how I currently do it.
private void Form1_Load(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
imagerDataPanel1.OpenImager();
}
void BackgroundWorker1DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
unitInformationPanel1.PopulateUnitInformation();
batteryInformationPanel1.InitializeBatteries();
magStripeReaderPanel1.SetupPointOfSale();
}
Mind you those 3 panels that have different methods will change when they extend the Abstract panel to be StartWork(). unitInformationPanel is the main culprit for time consuming operations. It takes it about 3-5 seconds to get everything it needs.
Thank you for your time.

New Topic/Question
Reply




MultiQuote




|