using System;
using System .Collections .Generic;
using System .Drawing;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;
using MoveGraphLibrary;
namespace UserDrivenApplications
{
public class ClosableInfo : TextM
{
int nCloseSide;
Rectangle rcClose;
SolidBrush brushClose = new SolidBrush (Color .OrangeRed);
Pen penCross = new Pen (Color .White, 3);
// -------------------------------------------------
public ClosableInfo (Form form, Point ptAnchor, string txt, Font fnt, Color clr, bool show_frame, bool show_background, Color back)
: base (form, ptAnchor, txt, fnt, clr, show_frame, show_background, back)
{
CalcSizes ();
}
// -------------------------------------------------
public ClosableInfo (Form form, Point ptAnchor, string txt, Font fnt, Color clr)
: this (form, ptAnchor, txt, fnt, clr, true, true, SystemColors .Control)
{
}
// -------------------------------------------------
public ClosableInfo (Form form, Point ptAnchor, string txt, Font fnt)
: this (form, ptAnchor, txt, fnt, form .ForeColor)
{
}
// -------------------------------------------------
public ClosableInfo (Form form, Point ptAnchor, string txt, Color clr)
: this (form, ptAnchor, txt, form .Font, clr)
{
}
// -------------------------------------------------
public ClosableInfo (Form form, Point ptAnchor, string txt)
: this (form, ptAnchor, txt, form .Font, form .ForeColor)
{
}
// -------------------------------------------------
public ClosableInfo (Form form, TextM textm)
: this (form, textm .Location, textm .Text, textm .Font, textm .Color, textm .ShowFrame, textm .ShowBackground, textm .BackColor)
{
Visible = textm .Visible;
}
// ------------------------------------------------- CalcSizes
void CalcSizes ()
{
base .CalcSizes (ParentForm, Text, Font);
nCloseSide = Math .Max (Auxi_Geometry .RoundMeasureString (ParentForm, "Text", Font) .Height, 20);
nW += nCloseSide;
rcClose = new Rectangle (Area .Right - (nCloseSide + wAdd / 3), Area .Top + hAdd / 2, nCloseSide, nCloseSide);
}
// ------------------------------------------------- Location
new public Point Location
{
get { return (ptLT); }
set { Move (value .X - ptLT .X, value .Y - ptLT .Y); }
}
// ------------------------------------------------- Text
new public string Text
{
get { return (base .Text); }
set
{
if (!(string .IsNullOrEmpty (value)))
{
base .Text = value;
CalcSizes ();
DefineCover ();
}
}
}
// ------------------------------------------------- Font
new public Font Font
{
get { return (base .Font); }
set
{
base .Font = value;
CalcSizes ();
DefineCover ();
}
}
// ------------------------------------------------- Draw
new public void Draw (Graphics grfx)
{
if (visible)
{
if (ShowBackground)
{
grfx .FillRectangle (new SolidBrush (BackColor), Area);
}
if (ShowFrame)
{
ControlPaint .DrawBorder3D (grfx, Area, Border3DStyle .Sunken);
}
Auxi_Drawing .DrawText (grfx, Text, Font, 0, Color, new Point (Location .X + wAdd / 3, Location .Y + hAdd / 2), TextBasis .NW);
grfx .FillRectangle (brushClose, rcClose);
Point ptC = Auxi_Geometry .Middle (rcClose);
int cx0 = ptC .X;
int cy0 = ptC .Y;
int d = nCloseSide / 3 - 1;
grfx .DrawLine (penCross, cx0 - d, cy0 - d, cx0 + d, cy0 + d);
grfx .DrawLine (penCross, cx0 - d, cy0 + d, cx0 + d, cy0 - d);
}
}
// ------------------------------------------------- DefineCover
public override void DefineCover ()
{
CoverNode [] nodes = new CoverNode [] { new CoverNode (0, rcClose, MovementFreedom .Freeze, Cursors .Hand),
new CoverNode (1, Area) };
cover = new Cover (nodes);
}
// ------------------------------------------------- Move
public override void Move (int dx, int dy)
{
ptLT += new Size (dx, dy);
rcClose .X += dx;
rcClose .Y += dy;
}
// ------------------------------------------------- MoveNode
public override bool MoveNode (int i, int dx, int dy, Point ptMouse, MouseButtons catcher)
{
bool bRet = false;
if (catcher == MouseButtons .Left)
{
if (i == 1)
{
Move (dx, dy);
bRet = true;
}
}
return (bRet);
}
// -------------------------------------------------
new public static ClosableInfo FromRegistry (Form form, RegistryKey regkey, string name)
{
TextM textm = TextM .FromRegistry (form, regkey, name);
if (textm != null)
{
ClosableInfo info = new ClosableInfo (form, textm);
return (info);
}
else
{
return (null);
}
}
// ------------------------------------------------- FromFile
new public static ClosableInfo FromFile (Form form, BinaryReader br)
{
TextM textm = TextM .FromFile (form, br);
if (textm != null)
{
ClosableInfo info = new ClosableInfo (form, textm);
return (info);
}
else
{
return (null);
}
}
}
}