c# - How to show a picture box inside a panel on hover programmatically? -
i have following problem, because quite new don't know if asking right questions...hope can put me in right direction, in advance.
i have panel. inside there textbox(same size panel(140*40) , picturebox(smaller , in right top corner, 15*15).at moment able when mousehover
panel(and textbox) show picturebox image deleting in it. if pass mouse on picturebox himself dissapears, , want happens when mouseleave
textbox or panel.
a college told me must use parent property, have no idea how can that.
i don't know if explanation good, leave code here, can point me solution.
textbox
tbrole
, panel
pnrole
, picturebox
pbdeletex
:
tbrole.mousemove += (senderl, el) => { if (mousehover) { pbdeletex.visible = true; mousehover = true; } else { pbdeletex.visible = true; mousehover = false; } tbrole.backcolor = color.aliceblue; pnrole.backcolor = color.aliceblue; // je dois mettre ici le dodragdrop parce que sinon sa ne marche pas le doubleclick if (el.button == mousebuttons.left) { idroleg = idrolel; tbrole.bringtofront(); clrol = tbrole.backcolor; mousedown = true; tbrole.allowdrop = true; tbrole.dodragdrop(tbrole, dragdropeffects.move); } }; tbrole.mousehover += (senderl, el) => { if (mousehover) { pbdeletex.visible = true; mousehover = false; } else { pbdeletex.visible = false; mousehover = false; } tbrole.backcolor = pnrole.backcolor = color.aliceblue; }; tbrole.mouseleave += (senderl, el) => { pnrole.backcolor = color.bisque; tbrole.backcolor = color.bisque; if (mousehover) { pbdeletex.visible = true; mousehover = false; } else { pbdeletex.visible = false; mousehover = true; } };
i think happens because when hover mouse cursor on picturebox
, tbrole.mouseleave
fired. can check using breakpoint , see if happens actually. can code 2 boolean variablesfor instance can say:
tbrole.mouseleave += (senderl, el) => { booltext == false; if(booltext == false && boolpic == false) { pnrole.backcolor = color.bisque; tbrole.backcolor = color.bisque; pbdeletex.visible = false; } };
this happens:
- hover cursor on textbox.
booltext == true
,boolpic == false
- hover cursor on pic.
booltext == false
,boolpic == true
. mouseleave not fired - leave picbox.
booltext == true
,boolpic == false
- leave textbox.
booltext == false
,booltext == false
. mouseleave fires , picbox disappears.
so, have add code of mousehover , mouseleave of picturebox
, global variable boolpic == true
if mousehover fired , boolpic == false
when mouseleave fired. add same logic in mousehover , mouseleave of textbox. hope should work. :p
Comments
Post a Comment