Adding a home button to your wpf browser - c#

I can't seem to get the Home button in my wpf web browser to work. Do you guys have any idea?
I have tried:
WebBrowser1.GoHome();
But I'm reciving:
'System.Windows.Controls.WebBrowser' does not contain a definition for 'GoHome' and no extension method 'GoHome' accepting a first argument of type 'System.Windows.Controls.WebBrowser' could be found (are you missing a using directive or an assembly reference?)
However, other commands are working just fine, for example:
WebBrowser1.GoBack();

Try to assign a set URL to the button/save the location as a file. Consider it more like a bookmark:
string input = Microsoft.VisualBasic.Interaction.InputBox("Please set your home page", "Settings");

WebBrowser1.Navigate(Registry.GetValue(#"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main", "Start Page", "").ToString());
That will work for IE, for any other browser it gets...complicated...

Related

Can't use BackgroundImage property on a Button

I'm trying to set an image as button background as follows:
button.BackgroundImage = Properties.Resources.blue;
But I get an error that says:
'Button does not contain a definition for 'backgroundImage' and no accessible extention method 'BackgroundImagew accepting a first argument of type 'Button' could be found (are you missing a using directive or an assembly reference?)
button.Background = Brushes.Blue;
Is this the result you are trying to gather

open a PDF in windows Form

I am trying to load a pdf into a axAcroPDF using this method that I found here. but there isn't a this.axAcroPDF.LoadFile() there. The error message that I get says:
"AxacroPDFLib.AxacroPDF doesn't contain a defection for 'LoadFile' and
no Extension method excepting first method of a type
AxacroPDFLib.AxacroPDF could be found (Are you missing a using
directive or an assembly reference?"
So I double checked and there are Acrobat , AcroPDFLib, AxAcroPDFLib Referances in the WPF and user control.
Next I goggled this again and found this on YouTube that uses this.axAcroPDF.src =path; however I do not this option either. Please tell me if they have changed the LoadFile(path) to something else, or if there is a reference that I am missing?
axAcroPDF1.LoadFile(PDFPath.ToString());
axAcroPDF1.setShowToolbar(false); //disable pdf toolbar.
axAcroPDF1.Enabled = true;
Another solution is to set the src property of your Axacro control.

Using html <a> tag instead of LinkButton, can't access c# code-behind

I'm tryna create an ASP.NET Empty Web application that allows users to sign up and log in to access different pages from the public. I'm currently using a masterpage that holds the navigational links, using the html tag. However, for one of my buttons it is used to Sign Out of the user's account to redirect them back to the page where the public that isn't logged in are able to access. However, to use a code behind, it'll probably require me to use a LinkButton to access the c# code behind for my sign out code, which is
FormsAuthentication.SignOut();
Response.Redirect("Index.aspx");
However, if I use a LinkButton it is required for me to use a tag, which screws up my page layout (the navigational links). Is there a way I can use the tag and still access my c# code behind to implement the codes I've pasted above?
Anyway I tried this
<a id="signOutBtn" onclick="signOut_Click" onserverclick="signOut_Click" runat="server">Sign Out</a>
but I got this error:
Compiler Error Message: CS1061: 'ASP.masterpageuser_master' does not contain a definition for 'signOut_Click' and no extension method 'signOut_Click' accepting a first argument of type 'ASP.masterpageuser_master' could be found (are you missing a using directive or an assembly reference?)
Try runat="server":
<a runat="server" id="signOutBtn" onserverclick="signOut_Click">Sign Out</a>
And in your code behind, define your function:
public void signOut_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("Index.aspx");
}

C# How to add an image on button array buttons

How can I add an image on buttons of button array ?
Button[] mybuttons = new Button[] {Button1,Button2}; //My button array
mybuttons[1].image=new Bitmap("Click.jpg"); ///Gives Error
'System.Web.UI.WebControls.Button' does not contain a definition for 'Image' and no extension method 'Image' accepting a first argument of type 'System.Web.UI.WebControls.Button' could be found (are you missing a using directive or an assembly reference?)
C# is case sensitive. Also, you need to use an ImageButton and give it an ImageUrl, not a Button. The web control Button does not have an Image property.

How can you get a xaml element using C#?

I have a xaml page samplePage.xaml and its corresponding .cs file samplePage.xaml.cs. In this page there is a textBox textBox1.
Now I create an instance of the page:
PhoneApp1.samplePage s = new PhoneApp1.samplePage();
and after that, I would like to set the value in the text box by calling:
s.textBox1.Text = "whatever"
but it turns out there is an error message saying
'PhoneApp1.samplePage' does not contain a definition for 'textBox1'
and no extension method 'textBox1' accepting a first argument of type
PhoneApp1.samplePage' could be found (are you missing a using
directive or an assembly reference?)
I would like to know how to get the xaml element using C# code?
You textbox is probably private or protected. Add a wrapper in your page to expose the textbox, something like :
public TextBox TextBox1
{
get
{
return this.textBox1;
}
}
(mind the case)
Then just use the property from anywhere you want: s.TextBox1.Text = "whatever";
Good question, you'll need to use XamlReader.Load to load your page/control at runtime, then you'll be able to access the controls within it:
http://msdn.microsoft.com/en-us/library/cc189076(v=vs.95).aspx#using_xamlreaderload
http://blogs.silverlight.net/blogs/msnow/archive/2008/10/09/silverlight-tip-of-the-day-60-how-to-load-a-control-straight-from-xaml.aspx

Categories