1
Answer

Windows form control and sql authentication

ShugMagoo

ShugMagoo

19y
5.8k
1
I had an asp page accessing a database and wanted to do away with the asp and make it a Windows form user control. I moved my c# code into a control class and added it to my html page via the object keyword. Now I cannot access my database even though its the same code. Now that I don't have a webconfig file how do I authenticate users to access the database. Right now it does not even work for me on my 'localhost'. Any ideas? Thanks in advance. Pat
Answers (1)
0
Nilanka Dharmadasa
NA 5.2k 0 15y
Hi friend,


The reason is though you set the color to the brush, you don't have access to that brush outside button click event.

So change your code as follows.


        SolidBrush myBrush;//Define the varaible outside the methods.
       
        public Form1()
        {
            InitializeComponent();
            myBrush = new SolidBrush(Color.Black);//You set a default color as black.
           
           
pictureBox1.Paint += new PaintEventHandler(f1_paint);//Your picture box paint method

            //You can write your other code here, if you want.
        }

        private void f1_paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Graphics formGraphics = this.CreateGraphics();
            formGraphics.FillEllipse(myBrush, 20, 20, 40, 40);
            //You can write other drawing code as you like.
            //But use 'myBrush ' to draw.
            
        }


        private void button2_Click(object sender, EventArgs e)
        {          

            ColorDialog clrdlg = new ColorDialog();

            if (clrdlg.ShowDialog() == DialogResult.OK)
            {

                myBrush = new SolidBrush(clrdlg.Color);
                pictureBox1.Refresh();
            }
        }





If you find this answer helpful, please do not forget to  check 'Do you like this answer' checkbox.

0
Kirtan Patel
NA 35k 2.8m 15y
Friend what are you doin with that PictureBox because after changing... the color of Brush you need to DrawSomthing with that brush ...then you can see color changed or not .
0
James
NA 3 0 15y
Hi Kirtan

Thaks very much for replying to my question with the code.  I added this code but unfortunately it didn't work. when I click on the button, the color dialog window opens, i select a new color for the brush, paint on the grid again but the color has not changed.  I also tried this code, but it didnt work.
 private void button2_Click(object sender, EventArgs e)
{

SolidBrush myBrush;

ColorDialog clrdlg = new ColorDialog();

if (clrdlg.ShowDialog() == DialogResult.OK)
{

myBrush = new SolidBrush(clrdlg.Color);

}
}
I used myBrush as this is what I am using earlier in the code as my brush object. I also tried this code but it didn't work.
 private void button2_Click(object sender, EventArgs e)
{

SolidBrush myBrush;

ColorDialog clrdlg = new ColorDialog();

if (clrdlg.ShowDialog() == DialogResult.OK)
{

myBrush = new SolidBrush(clrdlg.Color);
pictureBox1.Refresh();

}
}
Do you know why this isn't working?  Do you have any suggestions on how I can resolve this issue?  Thanks for your time.

Kind regards
0
Kirtan Patel
NA 35k 2.8m 15y
Friend , Here is Code you need .!!

 private void button1_Click(object sender, EventArgs e)

        {

            SolidBrush brush;

            ColorDialog clrdlg = new ColorDialog();

            if (clrdlg.ShowDialog() == DialogResult.OK)

            {

                brush = new SolidBrush(clrdlg.Color);

            }

 

            //Now use the Brush where you need

 

            // Thats it

 

        }