1

i have a web browser that it's edit mode is on and sum users work with it.

users can insert image but not with UI of web browser control but they select an image from a form and i insert them by code below :

private void insert_image_btn_Click(object sender, EventArgs e)
{
    HtmlElement userimage = webBrowser1.Document.CreateElement("img");
    userimage.SetAttribute("src", "image location");
    userimage.Id = "imageid";
    webBrowser1.Document.Body.AppendChild(userimage);
}

and i want to write some code that users can change the alignment of any image that inserts in web browser, i give them a combo Box that can select the alignment they want. but problem is that when they click on an image then change the combo Box value i can't find what image was clicked by user to change alignment.

how i can find what image are selected?

i find it's solution

private void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e)
{
e.ReturnValue = false;
selectedElement = webBrowser1.Document.GetElementFromPoint(e.MousePosition);

string tag = selectedElement.TagName;
if (tag == "IMG")
{
alignmentTscb.Enabled = true;
alignmentTscb.Text = selectedElement.GetAttribute("align");
}
else
alignmentTscb.Enabled = false;
}

selectedElement is the element that user right Click on it.

4

1 回答 1

1

You could store the image controls in an array and have a class level variable that tells you which one was last clicked.

In the click event handler of the image you can set the variable.

When a value in the dropdown box is selected you can check the variable to see which image was clicked on last. Then look at the array of images and align as necessary.

Let me know if you need a code example.

于 2013-04-12T14:48:25.813 回答