Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static string ShowBox(string txtMessage, string txtTitle)
       {
           newMessageBox = new CustomMessageBox();
           newMessageBox.lblTitle.Text = txtTitle;
           newMessageBox.lblMessage.Text = txtMessage;
           newMessageBox.ShowDialog();
           return Button_id;
       }


C#
private void CustomMessageBox_Paint(object sender, PaintEventArgs e)
{
    Color cl = Color.Blue;
    Graphics mGraphics = e.Graphics;
    //Pen pen1 = new Pen(Color.FromArgb(96, 155, 173), 1);
    pen1 = new Pen(cl);   //For Border color of message box
    Rectangle Area1 = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
    //LinearGradientBrush LGB = new LinearGradientBrush(Area1, Color.FromArgb(96, 155, 173), Color.FromArgb(245, 251, 251), LinearGradientMode.Vertical);
    LGB = new LinearGradientBrush(Area1, cl, Color.FromArgb(245, 251, 251), LinearGradientMode.Vertical); // For BackColor
    mGraphics.FillRectangle(LGB, Area1);
    mGraphics.DrawRectangle(pen1, Area1);
}
Posted
Updated 16-Nov-15 20:09pm
v2

1 solution

You set this variable in your calling code
C#
newMessageBox.lblTitle.Text = txtTitle;

which means you have passed the value to the new instance of the class CustomMessageBox, hence it is available for all non-static class methods.

However, I don't see that you are using lblTitle.Text inside
C#
private void CustomMessageBox_Paint(object sender, PaintEventArgs e)

So what do you expect to happen?

That said, a little Object Oriented pointer.
It is not a good practice to expose private member variables to the outside world like you do with lblTitle.Text
Better wrap this variable in a public property:
C#
public string DialogTitle
{
    get
    {
        return lblTitle.Text;
    }
    set
    {
        lblTitle.Text = value;
    }
}

This is what they call encapsulation.
 
Share this answer
 
Comments
Sathish km 17-Nov-15 3:47am    
thnks.. can u explain use of static which in simple..
George Jonsson 17-Nov-15 5:04am    
Well, a static member belongs to the type rather than the class and is considered to be initialized default. A static member comes into existence before a static constructor is called.
This means that you don't need to create an instance of a type to access it's static members.


A static method can be useful when you want to collect methods of similar usage into one class, but don't want or need to modify any internal fields.
Examples are Debug.WriteLine or int.TryParse.

A static field can be used in a singleton pattern to share the same variable between instances of the same class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900