WinForm ScrollViewer - c#

I have an application in WPF that uses ScrollViewr and I want to port it to WinForms, is there an equivalent control for WinForms?
Reason:
WPF program is slow and I can't seem to learn how to render the program properly (GameOfLife).
Code:
<ScrollViewer Name="displayPlaceHolder" HorizontalScrollBarVisibility="Auto">
<Canvas Name="display" MouseMove="display_MouseMove" MouseDown="display_MouseDown" Cursor="Cross" KeyDown="global_KeyDown" Focusable="True" />
</ScrollViewer>

You could try to use Panel with AutoScroll property enabled.

Related

How can I set Opacity of WebView2 control in WPF

How can I set Opacity of WebView2 control in WPF
I need to change opacity of WebView2 from 0 to 1 by using Storyboard but when I am trying to set "Opacity =0" to WebView2 it doesn't get apply.
So is there any way I can dynamically set its opacity?
WebView2 is not a native wpf control,it does not support transparency settings.
you can use CEFSharp,it provides the same feature of WebView2, and supports transparency settings.
NuGet\Install-Package CefSharp.Wpf -Version 108.4.130
It's simply impossible. WebView2 is HwndHost. it means they are native win32 windows placed exactly in location of specified in your WPF. So It's not a WPF element you can manipulate.
If you want to somehow hide the WebView for a while, you can use Visibility.
<wv2:WebView2 Visibility="Hidden" MinHeight="300" />
Above that control you can show a loading icon or something and animate it, not the WebView itself.
<Grid>
<wv2:WebView2 Visibility="Hidden" Width="500" Height="500" />
<custom:MyFancyLoadingControl Visibility="Visible" Width="500" Height="500" />
</Grid>

How to change the back ground color of winforms panel when it hosted in WPF?

I want host a winform Panel control in WPF by using WindowsFormsHost,after that,I found that I can't change the backcolor of hosted panel,or it's not working when you set BackColor="SomeColor".Any one has an idear?
<WindowsFormsHost Grid.Row="1">
<WinForms:Panel x:Name="VideoPanel" BackColor="Black" Dock="Fill"/>
</WindowsFormsHost>
I have found a solution,set window AllowsTransparency="False"

Let user resize control (textbox, specifically) in Canvas UWP

I have a canvas with a button that the user can press to add a new textbox to the canvas. How can I make it so the user can resize the text box by clicking and dragging on any of the corners of the textbox. Because the textbox is created in the C# code (not XAML), I would prefer code in C# not XAML.
Thanks
EDIT: My question is different than the one referenced because it is in UWP not WPF. These have very different controls. I would appreciate if you could translate the UWP information into UWP C#
You can use Thumb control instead of a textbox. The thumb control provides the functionality for you to write code to customize the drag and drop behavior. A simple code would be:
<Canvas x:Name="test">
<Thumb Width="100" Height="100">
<Thumb.Template>
<ControlTemplate>
<TextBlock HorizontalAlignment="Center" Text="12345"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Canvas>
A more complex sample could be found from this SO thread from Jay's answer. But please notice you need to customize the logic yourself in order to make it resize like what you need. The reference is just a direction.

What is the equivalent way to use Bitmap,Graphics,PictureBox & BitmapCopy() in WPF?

I'll try to explain my problem clearly.
I have a working code in WinForms that has a Board (PictureBox) that shows an image thats generated from a list of users controls (win-forms) by the function UserControl.BitmapCopy() for each user control.
This process begins with a blank image (Graphic type), and for each user control I draw it in a specific location with the function BitmapCopy() of the user control.
The result is an image that looks like a real form (with buttons,labels,etc.), but it’s just an image.
Then I show this image in a picture Box.
Now I need to implement this code in WPF, but I can’t generate an image of each user control with BitmapCopy().
I found this code that does it, so now I can generate a bitmap for each user control, but I don’t know what is the best way to create the Big Board that eventually shows a bitmap that has all the user controls images inside it, in different locations.
I would appreciate any help.
This is the equivalent in WPF:
<Window x:Class="MiscSamples.VisualBrush"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="VisualBrush" Height="300" Width="300" x:Name="Window">
<StackPanel>
<TextBlock Text="Hi, Im a Window!"/>
<TextBox Text="This is a TextBox"/>
<Slider Width="200"/>
</StackPanel>
<Window.ToolTip>
<ToolTip DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
<Grid Height="400" Width="400">
<Grid.Background>
<VisualBrush Visual="{Binding}"/>
</Grid.Background>
</Grid>
</ToolTip>
</Window.ToolTip>
</Window>
The Window's ToolTip consists of a grid painted with VisualBrush whose Visual is the Window itself. It looks like this:
As you can see, Exactly 0 lines of C# code are required to achieve the same in WPF.

XAML-embedded WinForms Panel doesn't support direct content?

I'm attempting to place a Winforms panel within my WPF UserControl, with the following code;
<WindowsFormsHost Grid.Row="3">
<WinForms:Panel>
<WinForms:TableLayoutPanel x:Name="myLayoutPanel" />
</WinForms:Panel>
</WindowsFormsHost>
Error:
The type 'Panel' does not support direct content.
I'm will then then initialise the TableLayoutPanel panel within C# code. Any ideas how I can workaround this error?
the Windows.Forms Panel Container is called Controls. You should be able to add it by doing something like this: If it were me I would just create a Winforms UserControl and add that to the WinFormsHost instead.
<WindowsFormsHost Height="100" HorizontalAlignment="Left" Margin="10,108,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="200">
<WinForms:Panel BackColor="Red" Dock="Fill">
<WinForms:Panel.Controls>
<WinForms:TableLayoutPanel x:Name="myLayoutPanel"/>
</WinForms:Panel.Controls>
</WinForms:Panel>
</WindowsFormsHost>

Categories

Resources