trying to change a picture box c# - c#

Im trying to make my picture change when a button is clicked so that the player can see the character attack. When they do so, so the picture should change to the attack image when the button is clicked and then back to the old image when the opponents turn starts.
All the images are saved in a folder named "images" inside the project folder, which is inside the "WindowsFormsApplication1" folder, but it says it cant find namespace images inside windowsformsapplication1
Here is the code I am using to change the image:
private void ArBut_Click(object sender, EventArgs e)
{
if (playerturn == true)
{
Ar.Image = global::WindowsFormsApplication1.images.archeratack.jpeg;
drhp = drhp - 15;
DrHP.Text = drhp.ToString();
checkend();
playerturn = false;
dratak();
}
}

You can't just set the image like that. First of all, because thats not a String, it thinks you are trying to access a code element. Obviously images is not a namespace or class within your code, so you get the compiler error.
You need to use PictureBox.Load (MSDN)
Ar.Load(#"./images/archeratack.jpeg");

You could try to create an Image object and use Image.FromFile("url")

Related

Changing Image to another Image in Resources folder (VisualStudio 2015 / c#)

I'm trying to change the Background Pic of a Button to another Pic that I saved in the Resources Folder. Currently The Code is the following (FinalDStagePickBANNED.png being the Pic I want it to change to):
private void FinalD_Click(object sender, EventArgs e)
{
BanFDButton.Image = (Image)Properties.Resources.ResourceManager.GetObject(FinalDStagePickBANNED.png);
}
The Thing is, that it apparently finds no Pics in the Resources-Folder, although there are like 10 pics.
Solved: The solution to the problem was to put the FinalDStagePickBANNED into quatation-signs, and to remove hte .png ending.

How to Show Other Forms Using DevExpress tileItem in tileControl?

I am new in C# and DevExpress. I'm trying to show another form by clicking a tile in the tileControl group but it doesn't show up. I just right-clicked at the tileControl, clicked view code and manually declared this since this doesn't automatically shows up if you double click a tile.
private void addTile_Click(object sender, EventArgs e)
{
var xForm2 = new XtraForm2();
xForm2.Show();
}
I just right-clicked at the tileControl, clicked view code and manually declared this since this doesn't automatically shows up if you double click a tile.
If I understand this correctly, you did not build your project using the C# code listed above, but only edited the source.
That does not work because what you edit in this way is not being loaded into the app.
Of course, I could be misunderstanding what you wrote.

No Image display in c#

I created a simple windows form application C#, that is supposed to show a picture. I am following a tutorial from here Following is the code of form1.cs
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
// Construct an image object from a file in the local directory.
// ... This file must exist in the solution.
Image image = Image.FromFile("Picture1.png");
// Set the PictureBox image property to this image.
// ... Then, adjust its height and width properties.
pictureBox1.Image = image;
pictureBox1.Height = image.Height;
pictureBox1.Width = image.Width;
}
}
The image is present in the solution folder, but still nothing is displayed in the window when the application is run. There is no compilation error.
Update
Its solved now.
Make sure the PictureBox click event handler is registrated. It is not sufficient to copy the example code. (I'm just guessing)
Without a full path, the image won't load from the solution directory.. it will load from the directory where your executable is executed from.. which is either the Debug or Release folders when you're running from Visual Studio.. depending on what Profile you're running it with.
So put the image in the /bin/Debug folder and run your program again.
A better option would be to add this image to the project and do either of the two:
Add as a resource. It can later be used with strong typing.
Set this option on the file: Copy to Output Directory = Copy if newer.
It is not a good practice to add anything manually under /bin/, because those folders are volatile and can be erased by Visual Studio at any moment (usually on the next rebuild).

How can I check if a PictureBox's image has been modified?

I'm working on a super top-secret application right now that has a PictureBox on it. There are some options to edit the image inside of the PictureBox, including (but not limited to) sepia, grayscale, and some rotations.
At the moment, however, there isn't any way to check if the image has been modified - as I've been trying to create a "Would you like you save your changes??!" dialog box, which would appear if the image has been modified in any way.
I've got all of the actual modifications set in stone at the moment - all I need is a reliable method of checking if the PictureBox's image has been modified.
mmm.. Every time the user use an option to edit the image, just set a flag to true. That way you know that the image has change.. in fact, you are changing it somehow, so you know when is modified!
Does the BackgroundImageChanged Event fire? Use that.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.backgroundimagechanged.aspx
There are some options to edit the image inside of the PictureBox,
including (but not limited to) sepia, grayscale, and some rotations.
private bool isChanged = false;
void Apply_sepia() {
isChanged = true;
// apply sepia
}
void close(...) {
if(isChanged) {
if(MessageBox.Show("Are you sure?", SomethingOptions.YesNo) == MessageBoxOptions.Yes) {
Application.Exit();
}
} else {
Application.Exit();
}
}
I obviously cannot remember what the correct property names are.. however you get the gist.

add one xaml based usercontrol to another on mouse event

I have three xaml files + their code behind files in my Silverlight (C#) web project.
One is the MainPage.xaml, which is what gets rendered in the browser.
The other two (lets call them Dot and Box) are custom usercontrols.
When the webpage loads, Dots get added to random locations in a sub-canvas in MainPage xml.
I would like to add a Box to a Dot's location when the user mouses over the Dot. Here is my code behind for Dot:
public partial class Dot : UserControl
{
public string grbId {get; set;}
public Dot()
{
// Required to initialize variables
InitializeComponent();
}
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
//
//HtmlPage.Window.Alert(grbId);
MainPage mp = new MainPage();
Box idWindow = new Box();
idWindow.textBlock.Text = grbId;
// I added the following two lines because I thought it was being
// rendered behind Skymap but that is not the case.
Canvas.SetZIndex(idWindow, 5);
Canvas.SetZIndex(mp.SkyMap, -1);
idWindow.IsEnabled = true;
// Grow is animation storyboard
idWindow.Grow.Begin();
// SkyMap is a canvas inside my LayoutRoot canvas in MainPage.
mp.SkyMap.Children.Add(idWindow);
}
}
The MouseEnter event fires properly and the HtmlPage alert works just fine. But the Box never gets drawn. I have added the same code to the MainPage OnLoad event and it works fine. Can someone please tell me what I am missing? I would appreciate any help you can provide.
Please let me know if I am leaving out important information to solve the problem. Thanks!
I had searched every keyword combo I could think of before posting this question. Apparently, they were not the keywords the search engines wanted.
I was able to finally find my answer here: http://forums.silverlight.net/forums/p/123126/278060.aspx

Categories