I have a big problem with a small matter. I'm coding a messaging app.
This is the layout I use: Main Form --> container (UserControl) --> bubble(UserControl)
I am sending these parameters to the container
this.container1.addOutMessage(message, get_min_sec(time), tickStatus);
and container creates bubbles dynamically in itself.
public void addOutMessage(string message, string time, int tick_status) {...}
According to the suggestion I got in this forum, I draw the contents of the message bubbles in the Paint event. Since the width and height information was not yet clear when creating, I could not create the vertical distance between the messages correctly.
That's why I created this function.
public void ContaninerConfigure()
{
int counter = 0;
int keepBottom = 0;
foreach (var item in container1.panel.Controls.OfType<Control>().OrderBy(ee => ee.TabIndex))
{
//SuspendDrawing(item);
if (item != null)
{
if (counter != 0)
{
item.Top = keepBottom + 10;
keepBottom = item.Bottom;
}
else keepBottom = item.Top + item.Height;
}
counter++;
}
counter = 0;
}
then
My problem starts here. When I add it to the container's resize event it works fine but when I call it in the main form after my messages are loaded it doesn't work at all. Paint event continues to run on every scroll movement. In the container's resize event, only the message bubbles that appear on the screen are aligned. It can crashes again when I scroll up. Then it is necessary to call the previous function again to align it.
I did not access Paint event in Bubble(UC) which is dynamically created in Container(UC).That's why I couldn't control with the paint event, its run or stop.
After some research I found the SuspendDrawing method. I implemented it this way but I don't want to use it. It takes 3 seconds for 25 bubbles to line up on the panel and main form stays "up to date" during compile.
There has to be a more practical way of doing this. For example, I don't know how to check the bool in the bubble(UC) from the main form.
If you have any idea about this issue, please help.