C# How to add an image on button array buttons - c#

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.

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.

How to create treelist click event in DevExpress?

My requirement is to develop a webpage where I have bind a treelist with database and based on user click on the treelist I have to show new textbox to add something to the Database. But using DevExpress I am unable to do that. Though I have found one sample answer from other forum which shows like below:
private void treeList1_Click(object sender, System.EventArgs e)
{
DevExpress.XtraTreeList.TreeList tree = sender as DevExpress.XtraTreeList.TreeList;
DevExpress.XtraTreeList.TreeListHitInfo info = tree.CalcHitInfo(tree.PointToClient(MousePosition));
if (info.HitInfoType == DevExpress.XtraTreeList.HitInfoType.Cell)
{
}
}
But when I try this on my asp.net project it can't find the XtraTreeList from the code behind and I am getting the following error:
The type or namespace name 'XtraTreeList' does not exist in the namespace
'DevExpress' (are you missing an assembly reference?)
Please help me on this. Thanks in advance.

Adding a home button to your wpf browser

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...

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