Any way to load an online image into a richtextbox - c#

I am trying to set an image into a richtextbox.
Can this be done and if so how?
Will I have to use an online textbox and load it into my form using the webbrowser, such as with monaco?
Using the properties menu, I do not see anything about images in the richtextbox, only backcolor, so I tried changing the backcolor to "transparent" because I thought of putting an imagebox under it and setting the link of the image there(say this one: https://media.tenor.com/images/cdcf2410001a5c02bcd371d13743aa57/tenor.gif)
Can anyone help me with this?

In WPF, you can add a BlockUIContainer to the document of your richtextbox. This allows you to input an IElement and display it as part of the document. This is great because that means you can input a picture here aswell.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.documents.blockuicontainer?view=netframework-4.8
Sample:
<RichTextBox HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" BorderBrush="Gray">
<FlowDocument>
<BlockUIContainer>
<!-- Here you can input any wpf controls, like the Image control. -->
<Image Height="100" Width="100" Source="C:\Some\Image.png" Stretch="Fill"/>
</BlockUIContainer>
</FlowDocument>
</RichTextBox>
Here's an stackoverflow answer that shows how to add an image from the web:
Showing image in WPF using the URL link from database

Related

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.

How to prevent image control from being "selectable" / show selection border?

I have 2 images in a Gridview, and when I run my app the images have a border around them when I mouseover. (see behaviour ->)
Behaviour
Can this be disabled, I've tried all the settings which seem related, such as:
Image x:Name="image1" Height="67" Width="67"
Source="ms-appx:///Assets/logo67.png"
HorizontalAlignment="Right"
IsDoubleTapEnabled="False"
IsHoldingEnabled="False"
IsRightTapEnabled="False"
IsTapEnabled="False"
ManipulationMode="None"/
You need to edit the GridViewItem template, which have default value here https://msdn.microsoft.com/en-us/library/windows/apps/mt299127.aspx
Create a custom style and apply it using ItemContainerStyle property of GridView

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.

Border for WebBrowser control

First i have created a web browser control(full screen sized) and then i have created a border above the web browser control but when i debugged it, the border is not visible. Need help? Thanks in advance for your hard work!
<Border x:Name="UrlBorder" Background="{StaticResource PhoneAccentBrush}" CornerRadius="8">
<TextBox x:Name="UrlTextBox" Background="White" InputScope="URL" Margin="0,0,98,0"/>
</Border>
<phone:WebBrowser x:Name="BrowserHost" Margin="0,12,0,0" Grid.RowSpan="2" GotFocus="BrowserHost_GotFocus" IsScriptEnabled="True" />
Not sure what you are trying to do here. Looks like you want an url input textbox surrounded by border on top of a nearly-fullscreen web browser element. If so, I would use a stackpanel.
<StackPanel>
<Border><TextBox /></Border>
<WebBrowser/>
</StackPanel>
If you want to hide the url input, you can still set the Border's visibility to Collapsed.
Elements in grid can overlap each other. So, the webbrowser element will cover your bordered textbox if it's fullscreen. Also, neither your border, nor your textbox has explicit height nor width.

Bing Maps (Silverlight) maps - specifying canvas to be at foreground through XAML

Below is the XAML code i have for a Bing Maps Silverlight weather related implementation.
Here is what i am trying to do:
Have a bing maps with several (over 100) pushpins- on mouseover - show a contentpopup (canvas=myPopup) below. Simple enough.
Everything works fine - however, when mypopup displays on mouseover, it is not on the foreground (the other pins appear on top of the contentpopup) - hence making it not very readable.
Question:
How do i specifiy the myPopup canvas specified in XAML below to always appear in the foreground, i.e. top most of the Bing Maps silverlight control when a user views it on mouseover.
Thanks!
<Grid x:Name="LayoutRoot" Background="White">
<m:Map x:Name="GlobalMap" Mode="Road" Center="15,7" ZoomLevel="2" CredentialsProvider="{StaticResource MyCredentials}" Margin="-70,-40,-100,-72">
<m:MapLayer x:Name="myLayer">
<Canvas x:Name="myPopup" Visibility="Collapsed" Opacity="1">
<Rectangle x:Name="myPopupRectangle" Fill="White" Canvas.Left="0" Canvas.Top="0" Height="100"
Width="100" RadiusX="15" RadiusY="15"/>
<StackPanel Canvas.Left="8" Canvas.Top="8">
<TextBlock x:Name="myPopupTexts" FontSize="5" Width="100">
</TextBlock>
</StackPanel>
</Canvas>
</m:MapLayer>
</m:Map>
</Grid>
Try adding Canvas.ZIndex to the MapLayer element, give it a large value like 200 or add your push pins to another MapLayer (rather than adding the pins directly to the map) that appears ahead of this popup layer in document order.
I did something similar to this, but took a different approach. What I did was create a custom pushpin template and create a PopUp within the template.
When the user hovers over the pushpin, the popup is displayed. Using the PopUp will solve your problem, since the control will automatically position it on top of everything. Try wrapping the Canvas in a PopPup and see if that works.
hth

Categories

Resources