Link to home
Create AccountLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

How to call for a form that is declared as a variabel.

Hi,

I have this code below that calls for the form StickyNotes multiple times by its variabel.

I see the line:

StickyNotes sticky = null;
Sticky = new StickyNotes();
StickyNotes sticky = new StickyNotes();

What should I declare if I want to call the StickNotes form again in this methode:

        private void bbFont2_ItemClick(object sender, ItemClickEventArgs e)
        {
            fontDialog.Font = Properties.Settings.Default.FontNote;
            if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                Properties.Settings.Default.FontNote = fontDialog.Font;
                Properties.Settings.Default.Save();
               //Here is want to call the textbox rtbContent that resides on
                //the stickynotes form.


            }
        }      

This is the code that I have form the stickynotes:

  private void bbNewNote_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            StickyNotes sticky = new StickyNotes();
            sticky.gpclCaption.Text = "";
            sticky.rtbContent.Clear();
            sticky.lblCreation.Text = (DateTime.Now.ToString());
            sticky.FormClosed += new FormClosedEventHandler(sticky_FormClosed);
            sticky.Show();
        }
        //*------------------------------------------------------------*//
        void sticky_FormClosed(object sender, FormClosedEventArgs e)
        {
            StickyNotes sticky = (StickyNotes)sender;
            ListViewItem myItem = new ListViewItem(sticky.gpclCaption.Text, 0);
            myItem = lvNotes.Items.Add(myItem);
            myItem.SubItems.Add(sticky.rtbContent.Text);
            myItem.SubItems.Add(sticky.lblCreation.Text);
            myItem.SubItems.Add(sticky.Size.Width.ToString() + ", " + sticky.Size.Height.ToString());
            myItem.SubItems.Add(sticky.Location.X.ToString() + ", " + sticky.Location.Y.ToString());
            myItem.SubItems.Add(sticky.BackColor.R.ToString() + ";" + sticky.BackColor.G.ToString() + 

";" + sticky.BackColor.B.ToString());
            myItem.Selected = true;
            RefreshListView();
        }
        //*------------------------------------------------------------*//
        private void lvNotes_DoubleClick(object sender, EventArgs e)
        {
            OpenSticky(lvNotes.SelectedItems[0]);
        }
        //*------------------------------------------------------------*//
        private void OpenSticky(ListViewItem lvi)
        {
            string Title = lvi.Text;
            string Content = lvi.SubItems[1].Text;
            string Creation = lvi.SubItems[2].Text;
            string Size = lvi.SubItems[3].Text;
            string Location = lvi.SubItems[4].Text;
            string[] backColor = lvi.SubItems[5].Text.Split(';');
            StickyNotes sticky = null;
            foreach (Form frm in Application.OpenForms)
            {
                if (frm is StickyNotes)
                {
                    sticky = (StickyNotes)frm;
                    if (sticky.gpclCaption.Text == Title)
                    {
                        if (sticky.WindowState == FormWindowState.Minimized)
                        {
                            sticky.WindowState = FormWindowState.Normal;
                        }
                        sticky.BringToFront();
                        sticky.Select();
                        return;
                    }
                }
            }
            sticky = new StickyNotes();
            sticky.gpclCaption.Text = Title;
            sticky.rtbContent.Text = Content;
            sticky.lblCreation.Text = Creation;
            sticky.Tag = lvi;
            sticky.FormClosed += new FormClosedEventHandler(EditSticky_FormClosed);
            sticky.StartPosition = FormStartPosition.Manual;
            System.ComponentModel.TypeConverter converter = 

System.ComponentModel.TypeDescriptor.GetConverter(typeof(Point));
            sticky.Location = (Point)converter.ConvertFromString(null, 

System.Globalization.CultureInfo.InvariantCulture, Location);
            converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Size));
            sticky.Size = (Size)converter.ConvertFromString(null, 

System.Globalization.CultureInfo.InvariantCulture, Size);
            sticky.BackColor = Color.FromArgb(int.Parse(backColor[0]), int.Parse(backColor[1]), 

int.Parse(backColor[2]));
            sticky.Show();
        }
        //*------------------------------------------------------------*//
        void EditSticky_FormClosed(object sender, FormClosedEventArgs e)
        {
            StickyNotes sticky = (StickyNotes)sender;
            ListViewItem myItem = (ListViewItem)sticky.Tag;
            myItem.Text = sticky.gpclCaption.Text;
            myItem.SubItems[1].Text = sticky.rtbContent.Text;
            myItem.SubItems[2].Text = sticky.lblCreation.Text;
            myItem.SubItems[3].Text = (sticky.Size.Width.ToString() + ", " + 

sticky.Size.Height.ToString());
            myItem.SubItems[4].Text = (sticky.Location.X.ToString() + ", " + 

sticky.Location.Y.ToString());
            myItem.SubItems[5].Text = (sticky.BackColor.R.ToString() + ";" + 

sticky.BackColor.G.ToString() + ";" + sticky.BackColor.B.ToString());
            myItem.Selected = true;
            

Open in new window


Who knows the answer and is willing to help me?

Greetings,

Peter Kiers
Avatar of YZlat
YZlat
Flag of United States of America image

try something like this:

TextBox tb = sticky.Controls.Find("rtbContent", true).FirstOrDefault() as TextBox;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Peter Kiers

ASKER

Thanks. YZlat.