Mitja Bonca 557 Nearly a Posting Maven

If you have to call a method on some othe class, you always have to use a reference of that class to get access to the public method (private are not visible at all).

Mitja Bonca 557 Nearly a Posting Maven

Show me the code you have, otherwise I cannot tell you what can be wrong.
Thx.

Mitja Bonca 557 Nearly a Posting Maven

Do it like:

//Program.cs file:
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());// open Form1        
        }
    }
        //form1:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            new Form2().Show(); //open Form2 
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

You can pass it into constructor of the class and use it:

class Main
{
     Piece[,] board = new Piece[9, 8];
     private void GoToMath()
     {
          //code...
          MathFunction mf = new MathFunction(board); //pass data to other class
          board = mf.DoSomeWork();   //do some work there, and return data
     }   
}

class MathFunction
{
     Piece[,] board;
     class MathFunction(Piece[,] _board)
     {
           this.board = _board,
     }

     public Piece[,] DoSomeWork()
     {
          //do work...
          return this.board;
     }
}
Mitja Bonca 557 Nearly a Posting Maven

or:

txtDisplay.Text = txtDisplay.Text.Remove(txtDisplay.Text.Length - 1);
Mitja Bonca 557 Nearly a Posting Maven

This is a new question. Close this thread if you are satisfied with the answer, and create a new thread. We have to follow the forum`s rules.

I`ll be in touch there, bye.

Mitja Bonca 557 Nearly a Posting Maven

1st of all: Do not change your controls (textBox in this case) access modifier. Leave it as private (never change it to public, because this is the worst thing you can do). There ar plenty of other ways to access the control, but directly from inside the class (form) where the control is instantiated. Create a new public method in this form, add a parameter to it, and then call THIS form from some other class to update the control.

And you see what can brings you when changing access modifiers? As said, leave it as private.
Example:

class Login
{
     public void UpdatingTextBox1(string msg)
     {
          textBox1.Text = msg;
     }
}

class Form1:
//inside of your method which calls Login form:
Login l = new Login();
l.UpdatingTextBox1 = "some text to pass".
Mitja Bonca 557 Nearly a Posting Maven

Check this out:

Private Shared Sub Main(args As String())
	Dim [date] As DateTime = DateTime.Today
	Dim daysNames As String() = GetDaysNames([date])
			'use each day (or show it)
	For Each days As String In daysNames
	Next
End Sub

Private Shared Function GetDaysNames([date] As DateTime) As String()
	Dim daysInMonth As Integer = DateTime.DaysInMonth([date].Year, [date].Month)
	Dim daysNames As String() = New String(daysInMonth - 1) {}

	'do your code to fill the daysNames array

	'on the end:
	Return daysNames
End Function
Mitja Bonca 557 Nearly a Posting Maven

That you dont have two databases? So, inserting on one, and looking into the other? It might occur this (at least I have a couple of issues with it).

Mitja Bonca 557 Nearly a Posting Maven

try:

PictureBox[] pbs;
void textBox1_TextChanged(object sender, EventArgs)
{
    int num =0;
    if(int.TryParse(textBox1.Text, out num))
    {
        pbs = new PictureBox[num];
        int x = 20, y = 20;
        for(int i = 0; i < pbs.Lenght; i++)
        {
            pbs[i] = new PictureBox();
            pbs[i].Name = "pictureBox" + (i + 1);
            pbs[i].Location = new Point(x, y);  //location point
            pbs[i].Size = new Size(300,200); //custom!!
            this.Controls.Add(pbs[i]);

            //setting new point for next pictureBox:
            //this code will put 2 pictureBoxes in a row 
            //if more then 2, next two will be put in a new row:
            if(i % 2 == 0)
            {
                x = 20;
                y += 220;
            }
            else
                x += 320;
        }
    }
}

This is only an example code, you can position pictureboxes by your way.
Hope it helps.

Mitja Bonca 557 Nearly a Posting Maven

Yes, to extend Chris`s code:

//in TextChanged event hander of textBox1:
//
string myID = Convert.ToInt32(textBox1.Text.Trim());
SqlConnection conn = new SqlConnection("connString");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = @"SELECT Column1, Column2 FROM MyTable WHERE ColumnID = @param";
cmd.Parameters.Add("@param", SqlDbType.Int).Value = myID;
SqlDataReader reader = cmd.ExecuteReader();
if(reader.Read())
{
    textBox2.Text = (string)reader[0];
    textBox3.Text = (string)reader[1];
}
else
{
    textBox1.Text = "";
    textBox1.Text = "";
}
reader.Dispose();
cmd.Dispose();
conn.Dispose();

As you can see this example includes 3 textBoxes. 1st one is for inserting IDs, other two are for inserting data read from database.
Subscribe to TextChanged event of textBox1 control, and put this code inside of it.

Mitja Bonca 557 Nearly a Posting Maven

If it expects four digits, then its input cannot be in the form of an int. It must be a string. The number of decimal digits has no meaning in the 'int' type - it's not natively an decimal type. (It's actually a 32-digit binary type. It's just that C# lets you specify numeric constants as decimal text for convenience - nobody wants to type a 32-digit binary number...)

You say your "my method accepts integers onli", but that contradicts what you say here: "it accepts only 4 digits in the Year field"

One of those statements must be untrue. The 'int' type in C# and also Java (presumably Java is somehow involved if you have a JAR file) doesn't have any mechanism for representing leading zeroes.

So if your method only accepts integers, then by definition it can't care about leading zeroes because the 'int' type doesn't actually support that concept. And if your method accepts only 4 digits, then by defintion the data you're passing it can't be an 'int' because if it was, it wouldn't be able to tell whether there was a leading digit or not.

As far as the 'int' type is concerned, 999, 0999, 0000999, 0x3E7, and 0x00003E7 are all exactly the same thing. These different textual representations are completely indistingiushable in an 'int' because they all have the same binary representation: 0000001111100111.

Note that the leading zeroes are always present in the underlying representation. 'int' is 32-bits. If …

Mitja Bonca 557 Nearly a Posting Maven


bghtyhgfr5674456_120411_3215.

The last four digits the time, middle set the date.

How is 3215 the time?? What it represents? Seconds?
Because 32hours and 15 minutes cannot be in one day!

Mitja Bonca 557 Nearly a Posting Maven

1. Do you mean one reference? If so, there is no point in this. You can simple without any harm and time consumption create a new connection reference (connection conn = new connection("string");.
No. The command will take those data that are currently available on the server. So if command1 just occured before command2, command2 will take the new data, if not, there will be only old data available for the command2.

Mitja Bonca 557 Nearly a Posting Maven

1. all code goes in the class (form) where the contol (textBox) is.
2. Delegate name is optional, you choose it; what ever name you want; just make is reasonable
3. is you have to replace then use only equal mark "=".

Mitja Bonca 557 Nearly a Posting Maven

to "add" data to textBox you have to glue th text together by using "+=" operators:

textBox1.Text = "some text";
textBox1.Text += " new text";
//out put is "some text new text".

If you work over classes or maybe even threads, yes, you should use delegates to update textBox control.
In this case, create a new method, which will update textBox only. And pass the data to it:

public delegate void TextBoxDelegate(string message);

public void UpdatingTextBox(string msg)
{
    if(textBox1.InvokeRequired)
         textBox1.Invoke(new TextBoxDelegate(UpdatingTextBox), new object[]{ msg });
    else
    {
         textBox1.Text = msg;
         //in case if you want to ADD text to previuos one do:
         //textBox1.Text += msg + " ";
}

//always call this method to show a text in textBox1, like:
string data1 = "some text";
UpdatingTextBox(data1);

//later ones again:
string data2 = "new text";
UpdatingTextBox(data2);

//and so on...

Hope this helps clarifying how to use delegates and updating controls with them.

Mitja Bonca 557 Nearly a Posting Maven

Hi, check this link. Its all there.

Mitja Bonca 557 Nearly a Posting Maven

You can create a seperate custom class which will hold the data. In any of the form you must have a reference (which has to be instantiated only one - on beginning) to this class; so you can access to the data on the class. The data can be in some properties, or in some collections line generic list.


Example:

class DataClass
{
    public List<string> list;
    pubic DataClass
    {
        list = new List<string>();
    }
}

class Form1 //create and set data
{
    Form2 f2;
    void Method1() //can be a button_Click event
    {
        //open form2 and pass data
        DataClass dc = new DataClass();
        dc.list.Add("Some text 1");
        dc.list.Add("Some text 2");
        if(f2 == null)
             f2 = new Form2(dc);  //passing reference of dataClass to other form
    }
}

class Form2 //set data
{
    Form3 f3;
    DataClass dc;
    public Form3(DataClass _dc)
    {
         this.dc = _dc;
    }

    void Method2() //can be a button_Click event
    {
        //open form3 and pass data        
        dc.list.Add("Some text 3");
        dc.list.Add("Some text 4");
        if(f3 == null)
             f3 = new Form3(dc);  //passing reference of dataClass to other form
    }
}

class Form3 // get data
{
     DataClass dc;
     public Form3(DataClass _dc)
     {
          this.dc = _dc;
     }
     
     void Method3()
     {
         // get the data from data class
         
         foreach(string str in dc.list)
         {
              //each str value has a value from the list
              string text = str;                  
         }
     }
}

This is only one of examples how to add data on forms, and get the data back out.

Mitja Bonca 557 Nearly a Posting Maven

Anytime mate :)

Mitja Bonca 557 Nearly a Posting Maven

Sure you can do, but you cannot addd comboBox control to TextBox array. But you can add its text additionally, like:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs)
     sb.AppendLine(tb.Text);
//adding text from comboBox too:
sb.AppendLine(comboBox1.SelectedItem.ToString());

System.IO.File.WriteAllText(@"C:\myFile.txt", sb.ToString());
Mitja Bonca 557 Nearly a Posting Maven

I actually dont understand what is wrong with your code based on your description.

Do you want to try to add text from some other class to textbox?

Mitja Bonca 557 Nearly a Posting Maven

Get all the textBoxes into an array, and read them (using Text property) into a StringBuilder class. Then write all to a text file:

Textbox[]tbs = { textBox1, textBox2, textBox3 }; // add all of them in here
StringBuilder sb = new StringBuilder();
foreach(TextBox tb in tbs)
     sb.AppendLine(tb.Text);

System.IO.File.WriteAllText(@"C:\myFile.txt", sb.ToString());
Mitja Bonca 557 Nearly a Posting Maven

Why you dont get the image directly out of the cell? You dont need to parse it to object.

Example:

public Form1()
        {
            InitializeComponent();
            //creating image column:
            DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
            {
                imageColumn.Name = "colImages";
                imageColumn.HeaderText = "Images";
                imageColumn.Width = 100;
                imageColumn.ImageLayout = DataGridViewImageCellLayout.Normal;
                imageColumn.CellTemplate = new DataGridViewImageCell(false);
                imageColumn.DefaultCellStyle.NullValue = null;
            }
            //adding column to dgv:
            dataGridView1.Columns.Add(imageColumn);

            //adding one image to cell of dgv:
            dataGridView1.Rows.Add();
            Image pic= Image.FromFile(@"C:\1\backward.png");
            dataGridView1[0, 0].Value = pic;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //retreiving image form dgv:
            Image img = (Image)dataGridView1[0, 0].Value;
        }
Mitja Bonca 557 Nearly a Posting Maven
//form1
private void CreateAndCopy2DArray()
{
    string[,] arr1 = new string[170000, 2];
    string[,] arr2 = new string[170000, 20];
    Form2 f2 = new Forms(arr1, arr2);
    f2.Show();
}
//form2:
public Form2(string[,] arr_1, string[,] arr_2)
{
    //use these two variables here
}
Mitja Bonca 557 Nearly a Posting Maven

But dont forget to subscribe to TextChanged event in Form_Load event (like I showed you for other KeyPress event).

Mitja Bonca 557 Nearly a Posting Maven

hmm, sorry, your project is a .net applicaiton, not a windows app.
So you need an event for web app. There is no KeyPress event. There ar only these events.

You could use TextChecked event.
Just did this code for you, and it works fine.

bool bJump;
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (!bJump)
            {
                if (textBox1.Text.Length > 0)
                {
                    char lastChar = textBox1.Text.Substring(textBox1.Text.Length - 1)[0];
                    if (!char.IsLetter(lastChar))
                    {
                        bJump = true;
                        textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1, 1);
                        textBox1.SelectionStart = textBox1.Text.Length;
                        textBox1.SelectionLength = 0;
                    }
                }
            }
            else
                bJump = false;
        }
Mitja Bonca 557 Nearly a Posting Maven

You didnt just copy/paste my code?
For the event you have to SUBSCRIVE, not only copy it.
YOu can do:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

public partial class Parts_PMEWDirectorate : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
       this.txt_DirName.KeyPress += new KeyPressEventHandler(txt_DirName_KeyPress); //ADD THIS LINE OF CODE - this is subscribing!!
    }


    protected void btn_save_Click(object sender, EventArgs e)
    {
        btn_save.Enabled = false;

        lookups insert = new lookups();
        string result = insert.PMEWDirectorates_Insert(txt_DirName.Text.Trim(), txt_DirHead.Text.Trim());
        if (result == "0")
        {
            lbl_msg.ForeColor = System.Drawing.Color.Blue;
            lbl_msg.Text = "Successful";
        }
        else
        {
            lbl_msg.ForeColor = System.Drawing.Color.Red;
            lbl_msg.Text = result;
        }
        btn_save.Enabled = true;
    }



    private void txt_DirName_KeyPress(object sender, KeyPressEventArgs e)
    {
         if (e.KeyChar != '\b')
            {               
             //allows just letter keys    
             e.Handled = !char.IsLetter(e.KeyChar); 
         }
    }   
}
Mitja Bonca 557 Nearly a Posting Maven

I thought so...
So you have to do thia a bit differently to get the rows where the checkBox is added:

For Each row As DataGridViewRow In dataGridView1.Rows
	Dim chk As DataGridViewCheckBoxCell = TryCast(row.Cells(0), DataGridViewCheckBoxCell)
			'this row has a checked checkBox
			'do your code in here...
	If Convert.ToBoolean(chk.Value) = True Then
	End If
Next
Mitja Bonca 557 Nearly a Posting Maven

In which part of my code shall i add it?

??

Subscribe to the textBox_KeyPress event, this will rise every time user will type into textBox. While typing it will not allow to enter other chars then letters (letters only, so no special chars, or numbers).

Mitja Bonca 557 Nearly a Posting Maven

Why do you have this code then:

IsRowSelected = Me.dgv1.Rows(i).Cells(1).Value

This means you have in each row of 2nd column a boolean type of value.

If not, what value do you check there in 2nd column?

Mitja Bonca 557 Nearly a Posting Maven

Is your 2nd column type of bool? Does it hav true of false values?

Mitja Bonca 557 Nearly a Posting Maven

You can do on a very simple way:

Private Sub textBox1_KeyDown(sender As Object, e As KeyEventArgs)
	If e.KeyCode = Keys.Enter Then
		textBox2.Text = GetData(textBox1.Text.Trim())
	End If
End Sub

Private Function GetData(str As String) As String
	Dim strReturn As String = ""
	Select Case str
		Case "A001"
			strReturn = "My 1st company name"
			Exit Select
		Case "A002"
			strReturn = "My 2nd company name"
			Exit Select
	End Select

	Return strReturn
End Function

But this is an exmple code, I dont know where you will get the data, but this is one of choices to use (using switch statement).

Mitja Bonca 557 Nearly a Posting Maven

You mean that all the letters from string1 are in string2?
Is so, hericles solution will work, but partly, you need a break point of the for loop, when all indexes are reached.

hericles`s code needs to be modified a bit (and in VB):

Dim s1 As String = "an apple"
Dim s2 As String = "each apple is not an issue"

Dim s1Array As String() = s1.Split(" "C)
Dim bContains As Boolean = False
For i As Integer = 0 To s1Array.Length - 1
	If s2.Contains(s1Array(i)) Then
		bContains = True
	Else
		Exit For
	End If
Next
If bContains Then
	Console.WriteLine("All words that are in s1 are in s2 as well.")
Else
	Console.WriteLine("s2 does NOT contain all words from s1.")
End If
Mitja Bonca 557 Nearly a Posting Maven

:)
But there is all your were wanted. Why you ask question if you dont know how to make them work then?
I have only provided you a code that you required as said.
At least you can try it out; simply create a new Console project and copy/paste this code inside of it.
Then go line by line through the code to check whats going on. Its not really that complicated as it looks, truly.

Mitja Bonca 557 Nearly a Posting Maven

Will this be a windows application?

I did a simple example code in Console. Code simulates throwing dices by just pressing any key, and it does all you asked for.
To make this a win application try to use this code, but it should be a lot easier, because you wont need those boolean flages( two while loops). There user starts a new dice throw.

Check it out:

class Program
    {
        static void Main(string[] args)
        {
            List<int> listOfDices = new List<int>();
            Random r = new Random();
            bool bQuit = false;
            int dice;

            while (!bQuit)
            {
                Console.WriteLine("Please throw a new dice: just press any key to simulate.");
                string a = Console.ReadLine(); //not important just to  let user to stop the program
                dice = r.Next(1, 7);
                Console.WriteLine(String.Format("You throw: {0}", dice));
                listOfDices.Add(dice);
                if (dice == 6)
                {
                    Console.WriteLine("You got the six finally!!");
                    Console.WriteLine("---- Information: ----");
                    Console.WriteLine(String.Format("The number six was thrown in {0} arrempt.", GetAttempt(listOfDices.Count)));
                    Console.WriteLine(String.Format("The average all throws is {0}.", CalculateAverage(listOfDices)));
                    Console.WriteLine("End-------------------");
                    while (true)
                    {
                        Console.WriteLine("If want to continue throwing press a positive number, if you want to quit press zero.");
                        string answer = Console.ReadLine();
                        int myNum;
                        if (int.TryParse(answer, out myNum))
                        {
                            if (myNum > 0)
                                break;
                            else
                            {
                                bQuit = true;
                                break;
                            }
                        }
                        else
                            Console.WriteLine("This was not a number, repeat it!");
                    }
                }
            }
        }

        private static string GetAttempt(int number)
        {
            var work = number.ToString();
            if (number == 11 || number == 12 || number == 13)
                return work + "th";
            switch (number % 10)
            {
                case …
Mitja Bonca 557 Nearly a Posting Maven

Your are welcome. I hope you make it :)

Mitja Bonca 557 Nearly a Posting Maven

To allow letters only subscribe to KeyPress event of textbox, and put this code inside (dont copy/paste the event, just the code inside of it):

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //allows backspace key
            if (e.KeyChar != '\b')
            {
                //allows just letter keys
                e.Handled = !char.IsLetter(e.KeyChar);  
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

So you have to delete whole row in database?
For each row in gridview Create new command to use DELETE query statement, like;

//initialize connection..
//initialize command..
//open connection..
string query = @"DELETE FROM MyTable WHERE FileName @param";
command.Parameters.Add("@param", SqlDbType.VarChar, 50).Value = filepath; //get file file path from the cell of gridview.
Mitja Bonca 557 Nearly a Posting Maven

Write this query:

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'

For further info go here.

To get table name into comboBox, you can use dataReader class, and while looping through the database, add their names into comboBox:

string connectionString = @"yourConnStringHere";
using (SqlConnection sqlConn = new SqlConnection(connectionString))
{
    SqlCommand cmd = connection.CreateCommand();
    cmd.CommandText = "SELECT table_name AS Name FROM
              INFORMATION_SCHEMA.Tables WHERE TABLE_TYPE = 'BASE TABLE'";
    connection.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    while(readr.Read())
         comboBox1.Items.Add((string)reader[0]);
    reader.Dispose();
    cmd.Dispose();
}
Mitja Bonca 557 Nearly a Posting Maven

Sure its possible to use Regular expressions. But you have to be specific what you have to validagte.
About columns checking, do you have to check if there is the correct number of columns to suit the number of columns of dataTables (dataSet)?

Best option is to use data binding. So no manual columns creation, but use DataSource property of DGV, this will automatically create columns (each time).
Just dont forget to set dataSource to null when re-setting new data to dgv.

Mitja Bonca 557 Nearly a Posting Maven

:)
You are welcome.
bte, just take it easy... programming is about calmness, concentration and creativness.

bye

Mitja Bonca 557 Nearly a Posting Maven

Iam not sure what exactly you want, but you can create a class variable (type of integer) and when you get the 1st for the 1s time, asign this id to this class variable. And later simply use it.

If its not in any help, please provide us some code. It will be easier for us.
thx in advance.
bye

Mitja Bonca 557 Nearly a Posting Maven

You have to subscribe to a Click event of label control:

Public Sub New()
	'constructor
	label1.Click += New EventHandle(AddressOf label1_Click)
End Sub

Private Sub label1_Click(sende As Object, e As EventArgs)
	MessageBox.Show("label clicked.")
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Then you can instantiate a DataView.
A datatable (or DataSet, which is combinded with ore or multiple datatables) is an in-memory representation of a single database table. You can think of it as having columns and rows in the same way.
A dataview is a view on a datatable, a bit like a sql view. It allows you to filter and sort the rows - often for binding to a windows form control.

-----
Check here how to use it.

Mitja Bonca 557 Nearly a Posting Maven

Try it this way:

using system;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing; 

private void Button1_Click(object sender , eventargs e)
{
    PrintDocument pd = new PrintDocument();
    pd.PrintPage+= new PrintPage(printing);
    pd.Print();
} 

void printing(object sender , PrintPageEventArgs e)
{

   Bitmap bitmap = new Bitmap(datagrid1.width,datagrid1.height);
   datagrid1.DrawtoBitmpa(bitmap,datagrid1.ClientRectangle);
   e.Graphics.DrawImage(bitmap,new Point(50,50));
}
Mitja Bonca 557 Nearly a Posting Maven

try to use some more appropriate numeric checking (validation):

Dim intValue As Integer
		'value in textBox is integer
If Integer.TryParse(textBox1.Text, intValue) Then
End If

Dim decValue As Decimal
		'value is decimal (in case if you use decimals
If Decimal.TryParse(textBox1.Text, decValue) Then
End If
Mitja Bonca 557 Nearly a Posting Maven

nope.

Mitja Bonca 557 Nearly a Posting Maven

Instantiate newDataSet with different name variable. This way like you do, you override it, and all data from before are gone.

Mitja Bonca 557 Nearly a Posting Maven

1. set dataSource to null
2. bind it again.

Mitja Bonca 557 Nearly a Posting Maven

Use a separate form that is borderless as well and has an Opacity of .5. Make it slightly bigger than the main form. You can make the "drop shadow" invisible to clicks by using a combination of WS_EX_NOACTIVATE and WS_EX_TRANSPARENT in the CreateParams() function. Simply move the drop shadow whenever the main form moves.


check this code:

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        DropShadow ds = new DropShadow();

        public Form1()
        {
            InitializeComponent();
            this.Shown += new EventHandler(Form1_Shown);
            this.Resize += new EventHandler(Form1_Resize);
            this.LocationChanged +=new EventHandler(Form1_Resize);
        }

        void Form1_Shown(object sender, EventArgs e)
        {
            Rectangle rc = this.Bounds;
            rc.Inflate(10, 10);
            ds.Bounds = rc;
            ds.Show();
            this.BringToFront();
        }

        void Form1_Resize(object sender, EventArgs e)
        {
            ds.Visible = (this.WindowState == FormWindowState.Normal);
            if (ds.Visible)
            {
                Rectangle rc = this.Bounds;
                rc.Inflate(10, 10);
                ds.Bounds = rc;
            }
            this.BringToFront();
        }

    }

    public class DropShadow : Form
    {

        public DropShadow()
        {
            this.Opacity = 0.5;
            this.BackColor = Color.Gray;
            this.ShowInTaskbar = false;
            this.FormBorderStyle = FormBorderStyle.None;
            this.StartPosition = FormStartPosition.Manual;
        }

        private const int WS_EX_TRANSPARENT = 0x20;
        private const int WS_EX_NOACTIVATE = 0x8000000;

        protected override System.Windows.Forms.CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE;
                return cp;
            }
        }
    }
}