Create images in runtime/Dynamically

Last post 01-25-2008 8:14 AM by ca8msm. 9 replies.

Sort Posts:

  • Create images in runtime/Dynamically

    01-24-2008, 7:06 AM
    • Loading...
    • tje.gaab
    • Joined on 01-11-2008, 6:35 AM
    • Posts 39

    Hello

    My problem is that I don't know how to create an image to my webpage dynamically. On my webpage, I have a dropdownbox with four options. Autoposback is enabled. Dependent on witch of the options is choosed I create a different amount of labels and textboxes. I also need to create an image, but i don't know how to do that. 

    This is how I create a label: 

    Label_Dynamic[iCounter] = new Label();
    Label_Dynamic[iCounter].ID = "Label_Dynamic" + System.Convert.ToString(iCounter);
    Label_Dynamic[iCounter].Text = "Week/Day for service:";
    Label_Dynamic[iCounter].Style["Position"] = "Absolute";
    Label_Dynamic[iCounter].Style["Color"] = "#cb0022";
    Label_Dynamic[iCounter].Style["Font-Size"] = "10pt";
    Label_Dynamic[iCounter].Style["Top"] = "" + (6 + (iOffsetCounter * 42)) + "px";
    Label_Dynamic[iCounter].Style["Left"] = "0px";
    Label_Dynamic[iCounter].Visible = true;
    Panel_OnChangeType.Controls.Add(Label_Dynamic[iCounter]);

    Is it possible to create a picture in a way like this? I tried 'new Image();' but it didn't work...
    Hope you can help me...
  • Re: Create images in runtime/Dynamically

    01-24-2008, 7:18 AM
  • Re: Create images in runtime/Dynamically

    01-24-2008, 7:24 AM
    • Loading...
    • ca8msm
    • Joined on 11-29-2005, 10:57 AM
    • http://aspnetlibrary.com
    • Posts 2,145

    For a very basic example, have a look at the first piece of code in this article

    Mark,
    Join me at the new IT Community of the 21st Century: http://lessthandot.com

    Please remember to click "Mark as Answer" on this post if it helped you
  • Re: Create images in runtime/Dynamically

    01-25-2008, 2:58 AM
    • Loading...
    • tje.gaab
    • Joined on 01-11-2008, 6:35 AM
    • Posts 39

    Thanks for the links...

     I'll follow the articles and se if I can make it work...

     //Thomas

  • Re: Create images in runtime/Dynamically

    01-25-2008, 5:02 AM
    • Loading...
    • tje.gaab
    • Joined on 01-11-2008, 6:35 AM
    • Posts 39

    Sorry... I think you guys misunderstood me.

    I've expressed myself wrong :-(

    The thing is, that I don't want to 'Create' an image. I want is to place a small image on the page dynamically and have the oppotunity to remove it again.

    I have an image in '~/Images/' called info.jpg - which I want to place on my page.

  • Re: Create images in runtime/Dynamically

    01-25-2008, 5:08 AM
    • Loading...
    • ca8msm
    • Joined on 11-29-2005, 10:57 AM
    • http://aspnetlibrary.com
    • Posts 2,145

    Oh, I see. In that case you will need to create a dynamic control when the page loads, e.g

    Dim i As New Image

    i.ImageURL = "path to image" 

    myPanel.Controls.Add(i) 

     

     

    Mark,
    Join me at the new IT Community of the 21st Century: http://lessthandot.com

    Please remember to click "Mark as Answer" on this post if it helped you
  • Re: Create images in runtime/Dynamically

    01-25-2008, 7:23 AM
    • Loading...
    • tje.gaab
    • Joined on 01-11-2008, 6:35 AM
    • Posts 39

    Isn't that only possible in Visual Basic? My code is C#

    //Thomas

    ca8msm:

    Oh, I see. In that case you will need to create a dynamic control when the page loads, e.g

    Dim i As New Image

    i.ImageURL = "path to image" 

    myPanel.Controls.Add(i) 

     

     

  • Re: Create images in runtime/Dynamically

    01-25-2008, 7:32 AM
    • Loading...
    • ca8msm
    • Joined on 11-29-2005, 10:57 AM
    • http://aspnetlibrary.com
    • Posts 2,145

    tje.gaab:
    Isn't that only possible in Visual Basic? My code is C#
    No, you can use exactly the same objects and methods in C#.

    Mark,
    Join me at the new IT Community of the 21st Century: http://lessthandot.com

    Please remember to click "Mark as Answer" on this post if it helped you
  • Re: Create images in runtime/Dynamically

    01-25-2008, 8:03 AM
    • Loading...
    • tje.gaab
    • Joined on 01-11-2008, 6:35 AM
    • Posts 39

    Hmm ok.

    I'm sorry, but I don't know how to use it in C# then.

    In your example there's no semicolons?

    For the 'Dim' Visual Studio writes: "The type or namespace name 'Dim' could not be found (are you missing a using directive or an assembly reference?)"

    //Thomas

  • Re: Create images in runtime/Dynamically

    01-25-2008, 8:14 AM
    • Loading...
    • ca8msm
    • Joined on 11-29-2005, 10:57 AM
    • http://aspnetlibrary.com
    • Posts 2,145

    C# simply has different syntax to VB.NET. For C#, it would be something like

    Image i;

    i.ImageURL = "path to image";

    myPanel.Controls.Add[i];

    Either way, my point wasn't to give you code that you can copy and paste. If you do this, you won't learn anything. What you should do, is look at the objects and methods that I mentioned, look them up in the help file and see how they can be used. This way you will understand what you are actually doing rather than just copying an answer from something you found on the internet.

    Mark,
    Join me at the new IT Community of the 21st Century: http://lessthandot.com

    Please remember to click "Mark as Answer" on this post if it helped you
Page 1 of 1 (10 items)
Microsoft Communities
Page view counter