Strange browser issue - c#

I have a strange browser issue regarding my windows forms app.
I have placed a web browser in my form and I'm simply trying to load google.
The problem is that the browser is auto refreshing it every few seconds and it makes it useless.
I have used:
webBrowser1.Url = new Uri("http://google.com");
and
webBrowser1.Navigate("http://google.com");
And the result is the same. The page is still auto refreshing. It's the first time I'm facing this issue. Is there anyone who faced it and can help me?
I'm running the code on Visual Studio 2012 - windows 7 x64
EDIT:
Here is the code of the form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Navigate("http://google.com");
}
}
}

I can't see how you're wiring things up, but to me it looks like you're wiring WebBrowser.DocumentCompleted to navigate to Google. The problem is;
The WebBrowser.DocumentCompleted event occurs when the WebBrowser control finishes loading a document.
In other words, every time you get an event that the page has finished loading, you're calling webBrowser1.Navigate("http://google.com"); which reloads it again.

Related

Creating a round button for my WPF app in visual studio 2013. Problem here is onPaint() Method generate error asking me to enter some valid parameters

Creating a round button for my WPF app in visual studio 2013. The problem here is onPaint() Method generates error asking me to enter some valid parameters.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace CurrencyTeller
{
class CircularButton:Button
{
protected override void OnPaint (PaintEventArgs pevent)
{
GraphicsPath grpath = new GraphicsPath();
grpath.AddEllipse(0,0,ClientSize.Width,ClientSize.Height);
this.Region = new System.Drawing.Region(grpath);
base.OnPaint(pevent);
}
}
}
Error 3 Argument 1: cannot convert from 'CurrencyTeller.PaintEventArgs' to 'System.Windows.Forms.PaintEventArgs'
From what I can see, youre creating a Forms control, not a WPF control. Create a new "WPF User Control" in your Project and port your button to the template. Beware that Windows.Forms controls dont work in a WPF enviroment.
Best you look at some WPF Control tutorial.

VSTO Word - adding a table row on button click from task pane

I have a VSTO project where a click of a button on the ribbon, opens a new Word doc with a specific template, and opens it with a custom task pane. On that pane is a button, which when clicked, i want to add a row to a table which exists in the doc template.
Currently i'm just getting a 'command failed' exception at run time when the button on the task pane is clicked. Here is the whole class. As you can see i've tried two ways to do it, both fail:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using word = Microsoft.Office.Interop.Word;
namespace TestWordAddin2010
{
public partial class NewDescDMtaskPane : UserControl
{
public NewDescDMtaskPane()
{
InitializeComponent();
}
private void addSpare_Click(object sender, EventArgs e)
{
Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows.Add(Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows[1]); //this doesn't work
//word.Table wordTable = Globals.ThisAddIn.Application.ActiveDocument.Tables[1];
//wordTable.Rows.Add(wordTable.Rows[1]); //neither does this work
}
}
}
Any help appreciated.
Most likely your first table contains merged cells. Then you won't be able to access individual rows in the Rows collection.
As a workaround you could use the Selection object as follows:
ActiveDocument.Tables(1).Range.Select();
Application.Selection.Collapse();
Application.Selection.InsertRowsAbove();

How to retain values in my listbox between postbacks ASP.NET

I'm fairly new to asp.net, any help would be greatly appreciated. The program is really simple, I have two web pages, one contains a listbox and the other contains a textbox. The program is just meant to add items to the listbox from another page. My code on WebForm1 ,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestAppState
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string field1 = (string)(Session["id"]);
ListBox1.Items.Add(field1);
}
else
{
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}
}
}
Code on WebForm2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
namespace TestAppState
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Application["id"] = txtID.Text;
Response.Redirect("WebForm1.aspx");
}
}
}
You're almost there. In your btn_AddClick event you need to find all of the ListBox items that have been selected and save their values to the session. You could do this in any number of formats, but probably a simple comma separated list would be fine.
The in your Page_Load event on WebForm2, you can read that session value and either directly data bind the text box with your session value or do whatever you need to do beforehand to manipulate the data.
In the code-behind for your second form, you could also snatch values directly from the first form by using the Control.FindControl method. Query strings could be yet another option. Not to knock other answers but sessions can be tricky some times. Although they are an easy solution, they can be lost depending on your application and in some cases, depending on browser security settings. This is mainly a concern using HTTPS though. Another reference for this might be Cross-Page Posting in ASP.NET Web Pages.
There are many different ways to achieve what you need to do. My approach would be to embed both pages into one form and manipulate the data with JavaScript or jQuery and use WebMethods to prevent from using postbacks. It would be a much smoother presentation to the user as well.

Invalidate UserControl Error in C#

I created an UserControl and everything works great except for the properties. The problem is I lost all the Design Property in my UserControl.. to be more clear, i made a screenshot.
This is my UserControl
..and a ToolStrip sample
this is my sample code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel.Design;
namespace _Sample__User_Control
{
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(IDesigner))]
public partial class ClientsCollectionListBox : UserControl
{
public ClientsCollectionListBox()
{
InitializeComponent();
}
[Browsable(true)]
[DefaultValue("Hello")]
public string MyString { get; set; }
}
}
my User Control doesn't have the Design Property. Upon dragging the User Control to my form, there's still the Design Property but upon running or adding another instance to this control, i lost the display. Any help for this problem would be appreciated. Do i need to Invalidate on load?
SOLUTION:
Spelling error.. sorry.. please close this thread..
[Designer("Sytem.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(IDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(IDesigner))]

MessageBox.Show() fonts

Is there a way I can change the font types in a MessageBox.Show() to get bigger size, bold, italic styles?
You can always make your own MessageBox creating a new Windows.Forms class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MessageBoxFont
{
public partial class Message : Form
{
public Message(String text)
{
InitializeComponent();
tbxMessage.Text = text;
btnOK.Focus();
}
private void btnOK_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Then you can control the properties (like the font, size, color and the like) shown under the solution explorer. You initialize this form like this:
private void OpenMessageBox()
{
String text = "This is a sample error message";
Message message = new Message(text);
message.Show();
}
Its a work-around, however, easier to implement :)
I believe that those fonts are controlled by the operating system.
You could (however) make a custom dialog and put anything you want in there including custom fonts.
Here is the MSDN resource for custom dialogs.
http://msdn.microsoft.com/en-us/library/2chz8edb(VS.90).aspx
Have you thought of something like a customized message box (www.html-messagebox.com)?
For more customization such as building an irregular shaped message box (Homer Simpson's head), you are better off creating your own MessageBox-like implementation for your project.
Check this http://www.windowsdevelop.com/windows-forms-general/change-font-size-for-messageboxshow-dialogs-62092.shtml

Categories