Home > Enterprise >  C# text box similar to Sticky Notes in Windows
C# text box similar to Sticky Notes in Windows

Time:10-04

I would like to add rectangular regions with text like StickyNotes application in Windows. In Windows sticky notes you can add rectangular regions, and by clicking them you can change the text inside of them. Also in sticky Notes you can add these rectangular with the button click.

I would like to have a similar effect, but I don't know Which component should I use from the Visual Studio 2019 Toolbar Menu?

enter image description here

Sticky Notes after the click:

enter image description here

I am using Winform, Visual Studio 2019 and coding with C#.

CodePudding user response:

After little research I reliazed that I could be able to achive same effect with the Panel and FlowLayout. I created a main TodoListFlowLayout inside my Form and I created another button to control this TodoListFlowLayout. With the button click I populated the FlowLayout as below:

Random random = new Random(); // Make it critiacally depended.

private void button1_Click(object sender, EventArgs e)
{
    Panel toDoElement = new Panel();

    toDoElement.Name = "panel"   (TodoListFlowLayout.Controls.Count   1);
    toDoElement.BackColor = Color.FromArgb(123, random.Next(222), random.Next(222));
    toDoElement.Size = new Size(TodoListFlowLayout.ClientSize.Width, 50);

    TodoListFlowLayout.Controls.Add(toDoElement);
    TodoListFlowLayout.Controls.SetChildIndex(toDoElement, 0);  
                                                     
    toDoElement.Paint  = (ss, ee) => { ee.Graphics.DrawString(toDoElement.Name, Font, Brushes.White, 22, 11); };
    TodoListFlowLayout.Invalidate();
}

You can create click event by:

toDoElement.Click  = todo_Element_Panel_Click;

and the function by:

void todo_Element_Panel_Click(object sender, EventArgs e)
{

}

And lastly you can make it scrollable by

    TodoListFlowLayout.AutoScroll = false;
    TodoListFlowLayout.HorizontalScroll.Enabled = false;
    TodoListFlowLayout.HorizontalScroll.Visible = false;
    TodoListFlowLayout.HorizontalScroll.Maximum = 0;
    TodoListFlowLayout.AutoScroll = true; 

Output can be seen as below:

enter image description here

  • Related