[C#] UI does not stay on screen for more than a second

Hello,

I’m trying to create a simple user interface to display some text… I’m using CitizenFX.Core.UI. The below code works but only displays on screen for a second… literally… I have tried using while or do while loops but they just freeze FiveM… Any ideas? My end goal is to be able to toggle the UI with a chat message…

CitizenFX.Core.UI.Rectangle rect = new CitizenFX.Core.UI.Rectangle(new System.Drawing.PointF(0.1f, 139), new System.Drawing.SizeF(150, 50), System.Drawing.Color.FromArgb(210, 0, 10, 28));
            CitizenFX.Core.UI.Text txt = new CitizenFX.Core.UI.Text("", new System.Drawing.PointF(1.1f, 140), 0.40f, System.Drawing.Color.FromArgb(255, 255, 255, 255));
            txt.Caption = "TEST TEST TEST";
            rect.Draw();
            txt.Draw();
            rect.Enabled = true;
            txt.Enabled = true;

Thanks for your help

Matt

The draw needs to be used in a loop, but in the loop, you also need to include await Delay(0) to prevent the freezing.

1 Like