C
C#ā€¢7mo ago
SirDurpsalot

āœ… Winforms redraw question

To start: I am still a very early beginner in c# and winforms, so sorry if im asking something obvious. I am trying to make a personal desktop application for displaying games from a database. At first I had displayed the data in a datagridview but after getting a bit better at c# I was trying to add panels to a panel that had a picture and some text (see picture1 (ignore the text, I was still testing stuff)). Now I finally got the panels to be added programmatically, but now whenever I scroll through the panel that has autoScroll on the dynamically added panels with the game pictures get redrawn or reloaded (see picture2). Now what I was wondering is why this happens? I assume it has something to do with the fact that there are so many images (the panels themselves all have background images, the tag labels (the yellow and gray pieces) also are images) Below is the method I made to draw the panels https://pastebin.com/rZy6QNtP If any more info is needed to help, please let me know
Pastebin
drawGamePanel - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
No description
No description
10 Replies
SpReeD
SpReeDā€¢7mo ago
Since nobody answered, I'm gonna give it a try. First things first, WinForms isn't made for such fancy things, it uses GDI+ engine to draw the Windows. Which is fine as long as you don't do something extraordinary with animations, pictures and a lot of Controls. DoubleBuffer helps, but isn't the solution to everything. However, WinForms has it's limits. I would advice you to use WPF or Avalonia (Cross-Platform). Unlike WinForms, WPF doesn't use GDI+, but is built upon DirectX, so it's able to use your graphic card for rendering; GDI/GDI+ uses the CPU only. That opens a whole new world of fancy UI stuff like you obviously wanna do. Besides what I wrote; your cards should be a seperate UserControl with it's respective properties, like image, hours played, achievements, name, etc.
Omnissiah
Omnissiahā€¢7mo ago
still, that artifacts shouldn't happen
SirDurpsalot
SirDurpsalotOPā€¢7mo ago
I had a feeling I was pushing the limits. Guess its time to learn WPF. Thanks for the info. Guess ill have to start from scratch Oh yeah that would have been smart
SpReeD
SpReeDā€¢7mo ago
$wpf
MODiX
MODiXā€¢7mo ago
WPF is the DirectX and XAML powered, Windows-only desktop GUI framework. You should prefer to use this over Windows Forms where you can. Hello World in WPF: https://docs.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-wpf
SirDurpsalot
SirDurpsalotOPā€¢7mo ago
Anyone got any recommendations for good tutorials for total beginners? šŸ˜…
leowest
leowestā€¢7mo ago
for WPF? https://wpf-tutorial.com/ also with WPF u do not ever drag and drop controls like in winforms $rulesofwpf
MODiX
MODiXā€¢7mo ago
Rules of WPF:

āŒ Avoid the WPF Designer to eliminate a category of confusing bugs
āŒ Don't rely on Margin as the primary tool for layouts
āŒ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

āœ… Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
āœ… Rely upon XAML Hot Reload to design your app's UI at runtime
āœ… Use layout controls (Grid, DockPanel, etc) to support proper resizing
āœ… Use data binding to eliminate glue code and state synchronization issues
āœ… Use collection controls and DataTemplate to dynamically create lists of controls
āœ… Learn MVVM to create maintainable apps
āœ… Use the Dispatcher to update controls from non-UI threads
āœ… WPF's default controls can be easily modernized via $wpfuilibs
āœ… Include relevant XAML, code-behind, and ViewModel code for questions when possible
Rules of WPF:

āŒ Avoid the WPF Designer to eliminate a category of confusing bugs
āŒ Don't rely on Margin as the primary tool for layouts
āŒ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

āœ… Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
āœ… Rely upon XAML Hot Reload to design your app's UI at runtime
āœ… Use layout controls (Grid, DockPanel, etc) to support proper resizing
āœ… Use data binding to eliminate glue code and state synchronization issues
āœ… Use collection controls and DataTemplate to dynamically create lists of controls
āœ… Learn MVVM to create maintainable apps
āœ… Use the Dispatcher to update controls from non-UI threads
āœ… WPF's default controls can be easily modernized via $wpfuilibs
āœ… Include relevant XAML, code-behind, and ViewModel code for questions when possible
SirDurpsalot
SirDurpsalotOPā€¢7mo ago
Thanks a ton, excited to start learning WPF Thank to everyone who responded :yotsubless:
MODiX
MODiXā€¢7mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server