Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Customize title bar and solve window dragging in winform blazor hybrid

$
0
0

I use blazor hybrid development mode in winform. The problem now is to use web components instead of native title bar. I achieve the form of moving winform by dragging the titlebar in the following way, but it can be felt that it is not as smooth as the native control dragging, and there is a little lag. Is there any better way to solve this problem? I did not find this phenomenon in similar electron applications

<div class="top-row ps-3 navbar navbar-dark" @onmousedown="MouseDown"><div class="container-fluid"><a class="navbar-brand" href="">Avalonia Blazor Hybrid</a><button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu"><span class="navbar-toggler-icon"></span></button></div></div>@code{    public void MouseDown(MouseEventArgs args)    {        _isMoving = true;        var startPosition = Control.MousePosition;        _startWindLeft = startPosition.X - Program.MainWindow.Location.X;        _startWindTop = startPosition.Y - Program.MainWindow.Location.Y;        DragWindow();    }    public void DragWindow()    {        var mainWindow = Program.MainWindow;        while (_isMoving)        {            if (Control.MouseButtons != MouseButtons.Left || Form.ActiveForm != mainWindow)            {                _isMoving = false;                break;            }            var cursor = Control.MousePosition;            mainWindow.Location = new((int)(cursor.X - _startWindLeft), (int)(cursor.Y - _startWindTop));        };    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles