Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.64 KB | None | 0 0
  1. MyForm form = new MyForm();
  2. form.Location = PointToScreen(new Point(e.X, e.Y));
  3. form.Show();
  4.  
  5. [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
  6. public static extern IntPtr GetDesktopWindow();
  7.  
  8. protected override CreateParams CreateParams
  9. {
  10. get
  11. {
  12. var cp = base.CreateParams;
  13. cp.ExStyle &= 0x00080000; // WS_EX_LAYERED
  14. cp.Style = 0x40000000 | 0x4000000; // WS_CHILD | WS_CLIPSIBLINGS
  15. cp.Parent = GetDesktopWindow();
  16. return cp;
  17. }
  18. }
  19.  
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Linq;
  23. using System.Text;
  24. using System.Threading.Tasks;
  25. using System.ComponentModel;
  26. using System.Drawing;
  27. using System.Drawing.Drawing2D;
  28. using System.Drawing.Text;
  29. using System.Windows.Forms;
  30. using LollipopUIControls.UIManagers;
  31.  
  32. namespace Gamasis.Apps.Controls
  33. {
  34. public class FloatingButton : Button
  35. {
  36. public FloatingButton()
  37. {
  38. SetStyle((ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint), true);
  39. DoubleBuffered = true;
  40.  
  41. Size = new Size(50, 50);
  42. BackColor = Color.Transparent;
  43.  
  44. SF.Alignment = StringAlignment.Center;
  45. SF.LineAlignment = StringAlignment.Center;
  46.  
  47. AnimationTimer.Tick += new EventHandler(AnimationTick);
  48. }
  49.  
  50. #region Variables
  51.  
  52. Timer AnimationTimer = new Timer { Interval = 1 };
  53.  
  54. FontManager font = new FontManager();
  55. StringFormat SF = new StringFormat();
  56. Rectangle StringRectangle;
  57.  
  58. bool Focus = false;
  59. int margintop = 0, marginleft = 0, marginright = 0, marginBottom = 0;
  60. int xx;
  61. int yy;
  62.  
  63. float SizeAnimation = 0;
  64. float SizeIncNum;
  65.  
  66. string fontcolor = "#FAFAFA";
  67. string Backcolor = "#039BE5";
  68.  
  69. Color EnabledBGColor;
  70. Color EnabledBorderColor;
  71. Color StringColor;
  72.  
  73. Color DisabledBGColor = ColorTranslator.FromHtml("#B0BEC5");
  74. Color DisabledStringColor = ColorTranslator.FromHtml("#FAFAFA");
  75. Color NonColor = ColorTranslator.FromHtml("#e3e5e7");
  76.  
  77. Image bGImage = null;
  78.  
  79.  
  80. #endregion
  81.  
  82. #region Properties
  83. [Category("Custom")]
  84. public string BGColor
  85. {
  86. get { return Backcolor; }
  87. set
  88. {
  89. Backcolor = value;
  90. Invalidate();
  91. }
  92. }
  93. [Category("Custom")]
  94. public string FontColor
  95. {
  96. get { return fontcolor; }
  97. set
  98. {
  99. fontcolor = value;
  100. Invalidate();
  101. }
  102. }
  103.  
  104. [Browsable(false)]
  105. public Font Font
  106. {
  107. get { return base.Font; }
  108. set { base.Font = value; }
  109. }
  110.  
  111. [Browsable(false)]
  112. public Color ForeColor
  113. {
  114. get { return base.ForeColor; }
  115. set { base.ForeColor = value; }
  116. }
  117.  
  118. [Category("Custom")]
  119. public Image BGImage
  120. {
  121. get { return bGImage; }
  122. set { bGImage = value; }
  123. }
  124.  
  125. ImageSizeLevel bGimgSize = ImageSizeLevel.peque2;
  126.  
  127. public ImageSizeLevel BGimgSize
  128. {
  129. get { return bGimgSize; }
  130. set { bGimgSize = value; }
  131. }
  132. #endregion
  133.  
  134. #region Events
  135. protected override void OnMouseEnter(EventArgs e)
  136. {
  137. base.OnMouseEnter(e);
  138.  
  139. EnabledBGColor = Color.FromArgb(30, ColorTranslator.FromHtml(BGColor));//StringColor);
  140. EnabledBorderColor = Color.FromArgb(20, ColorTranslator.FromHtml(BGColor));//StringColor);
  141. Refresh();
  142. }
  143. protected override void OnMouseLeave(EventArgs e)
  144. {
  145. base.OnMouseLeave(e);
  146.  
  147. EnabledBGColor = ColorTranslator.FromHtml(BGColor);
  148. EnabledBorderColor = ColorTranslator.FromHtml(BGColor);
  149. Refresh();
  150. }
  151. protected override void OnMouseDown(MouseEventArgs e)
  152. {
  153. base.OnMouseDown(e);
  154.  
  155. EnabledBGColor = Color.FromArgb(30, StringColor);
  156. Refresh();
  157.  
  158. xx = e.X;
  159. yy = e.Y;
  160.  
  161. Focus = true;
  162. AnimationTimer.Start();
  163. Invalidate();
  164. }
  165. protected override void OnMouseUp(MouseEventArgs e)
  166. {
  167. base.OnMouseUp(e);
  168. Focus = false;
  169. AnimationTimer.Start();
  170. Invalidate();
  171. }
  172.  
  173. protected override void OnTextChanged(System.EventArgs e)
  174. {
  175. base.OnTextChanged(e);
  176. Invalidate();
  177. }
  178. protected override void OnSizeChanged(EventArgs e)
  179. {
  180. base.OnSizeChanged(e);
  181. //StringRectangle = new Rectangle(3, 0, Width - 6, Height - 6);
  182. }
  183. #endregion
  184.  
  185. protected override void OnResize(System.EventArgs e)
  186. {
  187. base.OnResize(e);
  188. //SizeIncNum = Width / 34;
  189. SizeIncNum = Width / 10;
  190.  
  191. }
  192.  
  193. protected override void OnPaint(PaintEventArgs e)
  194. {
  195. base.OnPaint(e);
  196.  
  197. var G = e.Graphics;
  198.  
  199.  
  200. #region Default rectangle
  201. //G.SmoothingMode = SmoothingMode.HighQuality | SmoothingMode.AntiAlias;
  202. //G.Clear(Parent.BackColor);
  203.  
  204. //StringColor = ColorTranslator.FromHtml(fontcolor);
  205.  
  206. //var BG = DrawHelper.CreateRoundRect(1, 1, Width - 3, Height - 3, 1);
  207. //Region region = new Region(BG);
  208.  
  209. //G.FillPath(new SolidBrush(Enabled ? EnabledBGColor : Color.White), BG);
  210. //G.DrawPath(new Pen(Enabled ? EnabledBorderColor : Color.White), BG);
  211.  
  212. //G.SetClip(region, CombineMode.Replace);
  213.  
  214. ////The Ripple Effect
  215. //G.FillEllipse(new SolidBrush(Color.FromArgb(30, StringColor)), xx - (SizeAnimation / 2), yy - (SizeAnimation / 2), SizeAnimation, SizeAnimation);
  216.  
  217. //G.DrawString(Text, font.Roboto_Medium10, new SolidBrush(Enabled ? StringColor : DisabledStringColor), R, SF);
  218.  
  219. #endregion
  220.  
  221. #region Circle
  222.  
  223. //G.SmoothingMode = SmoothingMode.AntiAlias;
  224. //G.Clear(BackColor);
  225.  
  226. //GraphicsPath bgbtn = new GraphicsPath();
  227. //bgbtn.AddEllipse(0, 0, Width - 5, Height - 5);
  228.  
  229. //GraphicsPath bgShadow = new GraphicsPath();
  230. //bgShadow.AddEllipse(0, 0, Width - 2, Height - 2);
  231.  
  232. //G.FillPath(new SolidBrush(NonColor), bgShadow);
  233. //G.DrawPath(new Pen(NonColor), bgShadow);
  234.  
  235. //G.FillPath(new SolidBrush(Color.DeepSkyBlue), bgbtn);
  236. //G.DrawPath(new Pen(Color.DeepSkyBlue), bgbtn);
  237.  
  238. #endregion
  239.  
  240.  
  241. ///----------------------------
  242. G.SmoothingMode = SmoothingMode.AntiAlias;
  243. G.Clear(Parent.BackColor);
  244.  
  245. StringColor = ColorTranslator.FromHtml(fontcolor);
  246.  
  247. //var BG = DrawHelper.CreateRoundRect(1, 1, Width - 3, Height - 3, 1);
  248. //Círculo principal
  249. GraphicsPath bgbtn = new GraphicsPath();
  250. bgbtn.AddEllipse(2, 0, Width - 6, Height - 6);
  251.  
  252. //Círculo para la sombra
  253. GraphicsPath bgShadow = new GraphicsPath();
  254. bgShadow.AddEllipse(2, 4, Width - 6, Height - 6);
  255.  
  256. // se dibuja la sombra
  257. G.FillPath(new SolidBrush(NonColor), bgShadow);
  258. G.DrawPath(new Pen(NonColor), bgShadow);
  259.  
  260. //sedibuja el círculo principal sobre la sombra
  261. G.FillPath(new SolidBrush(Enabled ? ColorTranslator.FromHtml(BGColor) : DisabledBGColor), bgbtn);
  262. G.DrawPath(new Pen(Enabled ? ColorTranslator.FromHtml(BGColor) : DisabledBGColor), bgbtn);
  263.  
  264. // Se da a la región forma de círculo/elipse
  265. Region region = new Region(bgbtn);//BG);
  266. G.SetClip(region, CombineMode.Replace);
  267.  
  268. //The Ripple Effect
  269. if (Enabled)
  270. G.FillEllipse(new SolidBrush(Color.FromArgb(30, EnabledBGColor)), xx - (SizeAnimation / 2), yy - (SizeAnimation / 2), SizeAnimation, SizeAnimation);
  271. StringRectangle = new Rectangle((int)bgbtn.GetBounds().Location.X, (int)bgbtn.GetBounds().Location.Y,
  272. (int)bgbtn.GetBounds().Size.Width, (int)bgbtn.GetBounds().Size.Height);
  273. G.DrawString(Text, font.Roboto_Medium15, new SolidBrush(Enabled ? StringColor : DisabledStringColor), StringRectangle, SF);
  274. if (bGImage != null)
  275. {
  276. float imgX = 0, imgY = 0;
  277. imgY = (bgbtn.GetBounds().Size.Height - (int)bGimgSize) / 2;
  278. imgX = ((bgbtn.GetBounds().Size.Width - (int)bGimgSize) + 2) / 2;
  279. G.DrawImage(bGImage, imgX, imgY, (float)bGimgSize, (float)bGimgSize);
  280. }
  281. }
  282.  
  283. protected void AnimationTick(object sender, EventArgs e)
  284. {
  285. if (Focus)
  286. {
  287. if (SizeAnimation < Width + 250)
  288. {
  289. SizeAnimation += SizeIncNum;
  290. this.Invalidate();
  291. }
  292. }
  293. else
  294. {
  295. if (SizeAnimation > 0)
  296. {
  297. SizeAnimation = 0;
  298. this.Invalidate();
  299. }
  300. }
  301. }
  302.  
  303. public enum ImageSizeLevel
  304. {
  305. peque = 12, peque1 = 24, peque2 = 32,
  306. maso = 48, maso1 = 56, maso2 = 64,
  307. grande = 72, grande1 = 86, grande2 = 96,
  308. monstruo = 128, monstruo1 = 256, monstruo2 = 512
  309. }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement