GoImage

I have a Goimage object and I need to set its image to a.jpg image that I have.

How can I accomplish that?
I tried the following:
[code]
public class ArrowImage : GoImage
{
public ArrowImage()
{ // ResourceManager rm = new ResourceManager("Arrow",
// Assembly.GetExecutingAssembly());

this.ResourceManager = new ResourceManager(“Arrow”,Assembly.GetExecutingAssembly());
this.name = “Arrow.jpg”;
}

[/code]
Iam still not getting the image and I know I need something else as well but I culd not find any speciffic examples in the manual.
Thanks Very much
Susan

If you search the sample sources, you’ll find examples of this.

It's also discussed in the User Guide and in the FAQ.
The hard part is getting the image in your application so that you can refer to the resources correctly when creating the ResourceManager.
Typically you'll have a resource file named "Form1.resx" as an Embedded Resource in your project, associated with your Form1 class. Create it by:
new ResourceManager(typeof(Form1))
Or you might have it in a separate RESX file, say "Images.resx":
new ResourceManager("WindowApplication1.Images", GetType().Assembly)
Also, if you just have one place from which you'll get images, you can specify a single ResourceManager as the default place for all GoImages, just executed once at application startup:
GoImage.DefaultResourceManager = new ResourceManager(...);
If all of your images are the same size, and if you are using Windows Forms, you can use an ImageList control. You can then set GoImage.ImageList individually, or set the static property GoImage.DefaultImageList once as the default property for all GoImages.

Thank you very much.

Susan

I get my image to display but I am unable to get it to display using the fixed width and height that I set it to. I have set the size but it doesn’t seem to be taking it. I have images that are all 32x32 and they appear to be showing up much smaller.

By default GoImage.AutoResizes is true, so that when you change the image that is shown (such as by setting the Name or the Index or ResourceManager or ImageList properties), it automatically changes its GoObject.Size.

So if you want a GoImage to always be a particular Size, even when you change the image that it displays, set GoImage.AutoResizes to false, set its Size to the dimensions that you want, and then set its Name or Index to what you want.
If you never change the "contents" of the image once it has been initialized, you don't need to set AutoResizes to false, since you can just set the Size after you specify the image.

Thank you for the quick reply.

I don't ever want to (or plan to) change the image contents once it has been initialized. I tried both setting AutoResizes = false and removing it completely and I cannot get any image to display larger than like 20x20.
Any thoughts?
If it helps, the image is currently residing in a rectangle. In the rectangle I have tried making it's width and height even larger than 32x32 thinking that maybe it's size was constricting the image. That doesn't work either.

What do you get when you try this code:

GoImage img = new GoImage();
img.Name = @"C:\Program Files\Microsoft Visual Studio 8\VB\VBWizards\FrameSetTemplates\NavWToc.bmp";
doc.Add(img);
GoGeneralNode and GoSimpleNode have a default image size of 20x20, with a minimum of 20x20 and a maximum of 100x200.
GoGeneralNode gn = new GoGeneralNode();
gn.Initialize(null, @"C:\Program Files\Microsoft Visual Studio 8\VB\VBWizards\FrameSetTemplates\NavWToc.bmp",
"NavWToc.bmp", "90x128", 1, 1);
gn.Image.Size = new SizeF(90, 128);
doc.Add(gn);
Of course, the actual BMP file might not be on your system with that path. It's a bitmap that's 90x128.

I have all of my images defined in a resource file (.resx). The images show up so I know that my code is finding them.

I am also not using "doc.Add(img)". I am setting the background of my node equal to the image.
Here are some code snippets:
GoImage img;
img = GetGoImage();
this.Background = img;
public GoImage GetGoImage() { GoImage itnimg = new GoImage(); itnimg.Size = new SizeF(32, 32);
itnimg.Image = Properties.Resources.myimage;
return itnimg;
}

What node class are you using? If you are using a GoTextNode, then the Background is always resized to fit around the Label, unless you set GoTextNode.AutoResizes to false, in which case the size of the Label is set to fit inside the size of the Background.

Also, regarding resources, you should use the Name property to refer to the resource, and set GoImage.DefaultResourceManager to your manifest resources' ResourceManager, so that serialization (e.g. copy and paste) will work automatically. Setting the GoImage.Image property doesn't leave enough information around for serialization to work, since Images are not serialized.
There's more discussion of this in the FAQ and User Guide.
I have a class called PersonNode that inherits from GoTextNode.
I took your advice and set the GoImage.DefaultResourceManager equal to my Resource file. Good call!
I am still unable to get the images to size correctly though.

itnimg.Name = “smiley_face”;

I figured it out two seconds after posting. Duh!

Thanks again for the quick reply.
Any thoughts on what might be wrong with the size? This whole image size thing is KILLING me! I don't understand why I can't control any of the sizes of my images.

I am just adding this post so you don’t think that I figured out the IMAGE SIZE issue. The size issue is the one I have had since the very beginning.

Something else that I noticed after I add parent nodes to the first node is that when I start clicking on each of the nodes, the rectangle that contains them gets highlighted (which has been the default action for selecting a node ever since I started using goDiagram) -however, now all of a sudden the rectangles begin to randomly grow in size.
Any ideas as to why the rectangles grow when I don't want them to and my images won't display using their correct dimensions?

Why are you using a GoTextNode? If you replace the GoTextNode.Background with a GoImage, the text will be on top of the image, obscuring it. But if you had set GoTextNode.AutoResizes to false, you should be able to set the GoTextNode.Background.Size as you please.

Is there a reason you aren't using a GoIconicNode, a GoSimpleNode, or a GoGeneralNode, depending on how many ports you want to use? That will (by default) display text next to the image, rather than overlapping it.

I am inheriting from a TextNode because I need the maximum number of ports. I want to be able to use BottomPort. I also don’t plan on having any text in the node. I am using tooltips to show my text. All I want is for the background to be the image that I want and at it’s proper size. For the life of me I can’t figure out what is restricting it.

I FIGURED IT OUT!!!

I needed to set the AutoResizes property of the Node itself to false -NOT the AutoResizes property of the image!!!
Thank you for all your assistance. I have never seen such a dedicated tech support person. You deserve a HUGE pat on the back (and probably a lot more than that)!!!
If your superiors are reading this they should make sure to keep you around.
Cheers!!!
PS: On a side note, how can I disable links from being created each time I click on a Port? It's very annoying when a user is either clicking or dragging a node and all of a sudden they've created like a whole bunch of links that zig-zag to other Ports.
PSS: I figured that one out too! this.DefaultLayer.AllowLink = false;

Thanks. That’s why we’re the leading diagram component.

Regarding your additional question, you could also do any of the following, depending on the scope to which you want to restrict linking behavior:
goView1.AllowLink = false; // for all layers in this GoView
goView1.Document.AllowLink = false; // for all views displaying this document
goView1.ReplaceMouseTool(typeof(GoToolLinkingNew), null); // no drawing new links in this GoView
goView1.ReplaceMouseTool(typeof(GoToolRelinking), null); // no reconnecting existing links in this GoView
textnode.TopPort.IsValidFrom = false; // for a particular node
textnode.TopPort.IsValidTo = false;
textnode.LeftPort.IsValidFrom = false;
textnode.LeftPort.IsValidTo = false;
textnode.RightPort.IsValidFrom = false;
textnode.RightPort.IsValidTo = false;
textnode.BottomPort.IsValidFrom = false;
textnode.BottomPort.IsValidTo = false;
foreach (IGoPort port in node.Ports) { // a more general way, when you don't know how many ports there are on a node
GoPort p = port as GoPort;
if (p != null) {
p.IsValidFrom = false;
p.IsValidTo = false;
}
}