Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Two C# Problems

Options
  • 05-02-2005 3:50am
    #1
    Registered Users Posts: 302 ✭✭


    Sorry if the answers to these are basic, but I'm struggling to solve them and can't find any answers where I normally would (or even those places I normally wouldn't) look...

    1. I am using a openFileDialog to browse for .ico files. I want to display the selected file in a label. The browser is working fine, and returns the object fine, and I have even used a toString method on the FileName of the returned file and displayed the address to check it. What I want to do is use this address (or an alternative method using the file returned by the openFileDialog) to display the selected file in a label. Any ideas?

    2. Secondly, at another point I need to use a folderBrowserDialog to set a destination address. I have written suitable code, but whenever the browser displays, the buttons and titles appear fine, but the middle section of the window, where the directory tree should display, is blank. Not an empty display, but nothing there, no box or area for anything to display. I have even tried running the folderBrowserDialog sample program from the MSDN, which works fine. But even c&p'ing the same code into my own results in the same problem. Any thoughts?


Comments

  • Registered Users Posts: 6,762 ✭✭✭WizZard


    1. I don't understand address. Do you mean the path? If so it's
    if(fd.ShowDialog() == DialogResult.OK)
    			{
    				string filePath = Path.GetFullPath(fd.FileName);
    			}
    

    2. No idea, have you set the start directory to an existing one? By default it starts with a special folder IIRC (e.g My Documents).


  • Registered Users Posts: 302 ✭✭kermitdfrog


    1. Sorry, was half asleep writing that so may not have been clear! Yeah, its the filepath I meant, not the address. I have done what you suggested already - that's not the problem. But I now want to use that string (or ANY other means) to display the image itself.
    this.openFile.DefaultExt = "ico";
    this.openFile.Filter = "ico files (*.ico)|*.ico";
    DialogResult result = openFile.ShowDialog();

    // OK button was pressed.
    if(result == DialogResult.OK)
    {
    string openFileName = openFile.FileName;

    It's the next part where the problem begins..
    //this is fine
    this.label10.Text=openFileName.ToString();

    //but what can I do here?
    this.pictureBox1.Image= ....?

    }


    2. Yeah the default folder has been set, re-set, changed, set again - it doesn't make any sense!!!


  • Registered Users Posts: 6,762 ✭✭✭WizZard


    1. I don't understand what image you want, is it to get the default icon for the file-type?

    2. No idea, maybe send me/post your code here


  • Registered Users Posts: 2,758 ✭✭✭Peace


    I think he's trying to load the picture/ico file and display it in an image control.

    You can't just say control.image = xxxx.... thats reference the image object of the control so you have to give it an image!

    You need to do a LoadImage/LoadPiture.

    From MSDN...
    // C#
    private void LoadNewPict(){
       // You should replace the bold image 
       // in the sample below with an icon of your own choosing.
       // Note the escape character used (@) when specifying the path.
       pictureBox1.Image = Image.FromFile
       (@"c:\something\whatever\itslate\i'mnackered\" + strFileName);
    }
    

    The @ means you don't have include all the double slashes like this "c:\\something\\whatever...."etc


Advertisement