I am having a web browser control in a winform. In order to show the web content completely (without scroll bars), I need to get the size of the web content in DocumentComplete event. And then resize(refresh) the winform.
void wbControl_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
wbControl.Height = wbControl.Document.Window.Size.Height;
wbControl.Width = wbControl.Document.Window.Size.Width;
}
But, Its not getting set from here. Old values remains the same.
If Document.Window.Size does not do the trick, Document.Body.ScrollRectangle will usually work for you.
I added some width and height when resizing the form because of the borders of the form, when resizing only the control itself this is not something you have to do.
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//If dockstyle = fill
this.Width = webBrowser.Document.Body.ScrollRectangle.Width + 40;//Border
this.Height = webBrowser.Document.Body.ScrollRectangle.Height + 40;//Border
//If the control is not docked
webBrowser.Size = webBrowser.Document.Body.ScrollRectangle.Size;
}
Related
I'm making a text editor, and it will have the ability to be resized. However when it is resized the close button along with a few other buttons at the top are kinda stuck in the middle. I would like to do something like this.
Ex.
private void Size_Change(object sender, EventArgs e) // Event after maximize or restore
{
Close_Button.Location = Width - (width of button);
}
what is a method of doing getting the width of a form and then subtracting from that width?
Just use anchor points on the button. Like Sani Singh Huttunen said. It's located in the properties of the button.
That way it will be resized or relocated with the form
you need change "Location" to "Left" property:
private void Size_Change(object sender, EventArgs e)
{
Close_Button.Left = this.Width - Close_Button.Width;
}
or create new Point to Location property.
There is a Button that changes its position vertically depending on which line the marker is installed in the RichTextBox. It is necessary that when I click on the Button the Panel (or UserControl, maybe it's better) appeared opposite the Button to the full width of the RichTextBox.
Panel should be located on the RichTextBox. That is, if the initial size of the form (500, 500) and this Panel is displayed from the edge to the edge of the RichTextBox, when the user changes the frame size to (500; 1000) and again presses the Panel display, this Panel should stretch and everything is also displayed on the RichTextBox. Below is the code for displaying the Button vertically and an animated GIF example of what I need.
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
var pos = richTextBox1.GetPositionFromCharIndex(richTextBox1.SelectionStart);
Point locationOnForm = panel1.FindForm()
.PointToClient(panel1.Parent.PointToScreen(panel1.Location));
Point newLocation = new Point(locationOnForm.X - 10, pos.Y + locationOnForm.Y - 13);
button1.Location = newLocation;
}
In the onClick method you could position the panel next to it?
private void MyButton_Click(object sender, EventArgs e)
{
MyPanel.Location = new Point(MyButton.Location.X + MyButton.Width, MyButton.Location.Y);
MyPanel.Visible = true;
}
And if you want it to be the same height as the button, add this line inside the method.
MyPanel.Size = new System.Drawing.Size(MyPanel.Width, MyButton.Height);
And for stretching it you can use your forms SizeChnged event
private void MyForm_SizeChanged(object sender, EventArgs e)
{
MyPanel.Width - MyButton.width + 5;
}
I have a winform application which contains a window resizable but one requirement is all UI items in the window should be resized according to size of the window. How can I achieve that?
Set the anchor properties on your controls. For example, if you set a control to anchor left and right, it's width will change as it's parent resizes. Same with top and bottom. Note, however, it will not resize, for example, the text inside a control.
I will give an example with a Winform named Simulator:
partial class Simulator
{
int oldWidth, oldWeight;
...
private void InitializeComponent()
{
... (generated initialization code)
this.ResizeBegin += new System.EventHandler(Simulator_ResizeBegin);
this.ResizeEnd += new System.EventHandler(Simulator_ResizeEnd);
}
void Simulator_ResizeEnd(object sender, System.EventArgs e)
{
this.oldWidth = this.Width;
this.oldHeight = this.Height;
}
void Simulator_ResizeBegin(object sender, System.EventArgs e)
{
int wider = this.Width - this.oldWidth;
int higher = this.Height - this.oldHeight;
// Change size of UI elements.
}
}
I have a Panel as a container this panel has a picture on it as a background, within the container panel, I have another panel where I gonna put some information in labels, that information will change in time, what I want is a transition when a new info is about to show, fade out the information panel with the old info and then fade in the same panel with the new info. At the time of the fade out the information panel I will be able to see the backgroud image of the container panel. Both panels have BorderStyle=FixedSingle, also the info panel has a backcolor color.
Now my question is: is there any way to fade in/out the information panel and the whole content within too?
I was searching in the web, and I found an approach to this effect working with the panel's backcolor but it doesn't work at all, and besides, the content still there, since they just try to fade the backcolor property:
Timer tm = new Timer();
private void Form1_Shown(object sender, EventArgs e)
{
tm.Interval = 100;
tm.Tick += new EventHandler(timer1_Tick);
tm.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
int aa = 0;
panel2.BackColor = Color.FromArgb(aa, 255, 0, 0);
aa += 10;
if (aa > 255)
tm.Enabled = false;
}
Any help will be appreciated.
I don't believe you can set the opacity of individual controls. The form itself has an opacity, but I don't think you want to fade out the whole control.
You can create custom controls that support opacity...here's an example:
http://www.slimee.com/2009/02/net-transparent-forms-and-controls-with.html
I believe this implementation would apply to child controls within the panel (because it is working on the rectangular area that the control takes up). If I'm wrong, you'd have to handle all of the child control's as part of your over-ridden behavior.
As others have said, getting this to look 'smooth' might be a lot of work. Hopefully someone will have a better answer.
As suggested in other answers, you can not (easily without your own controls) fade in/out a panel.
You can fade the form in or out at start up OR have a modal dialog form that fades in or out.
Fade In
private void FadeIn_Tick(object sender, EventArgs e)
{
this.Opacity += .08;
if (this.Opacity >= 1)
{
FadeIn.Stop();
}
}
Fade Out
private void FadeOut_Tick(object sender, EventArgs e)
{
this.Opacity -= .08; //Decrease opacity
if (this.Opacity <= 0) //While it is not 0
{
FadeOut.Stop(); //Stop!
this.Close(); //Close the form
}
}
my problem is quite simple: when user changes selection in a ListBox, I need my app to go to fullscreen mode, but I need to change the displayed page. I use Silverlight 4
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PresentationPage currentPresentationPage = new PresentationPage();
App.Current.RootVisual = currentPresentationPage;
App.Current.Host.Content.IsFullScreen = true;
}
When the code above is executed, the app goes to fullscreen, but the Page does not change, it only resizes. Can anybody tell me what's wrong with that code? Thanks
You can't change Application.RootVisual after it is assigned. What you need to do is include a panel that you can change it's content and make that panel your RootVisual.
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PresentationPage currentPresentationPage = new PresentationPage();
(App.Current.RootVisual as Panel).Children.Clear();
(App.Current.RootVisual as Panel).Children.Add(currentPresentationPage);
App.Current.Host.Content.IsFullScreen = true;
}
Then in your App's Startup event do something like so.
Panel grid = new Grid();
grid.Children.Add(new MainPage());
App.Current.RootVisual = grid;