Skip to content

Commit

Permalink
Prevented anything other than left click triggering BilgeButtons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Jul 28, 2017
1 parent ca07c33 commit cfea35c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions Source/Controls/BilgeButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ protected override void OnPaint(PaintEventArgs e) {
e.Graphics.DrawImageTranslucent(Image, Selected ? 1 : .75f, imageX - offset, imageY - offset);
}

protected override void OnClick(EventArgs e) {
// Only allow left click to raise click event.
if ((e as MouseEventArgs)?.Button.HasFlag(MouseButtons.Left) ?? false) {
base.OnClick(e);
}
}

private void BilgeButton_Click(object sender, EventArgs e) {
if (ToggleButton) {
Selected = !Selected;
Expand All @@ -133,13 +140,13 @@ private void BilgeButton_MouseLeave(object sender, EventArgs e) {
}

private void BilgeButton_MouseDown(object sender, MouseEventArgs e) {
if ((e.Button & MouseButtons.Left) > 0) {
if (e.Button.HasFlag(MouseButtons.Left)) {
IsMouseDown = true;
}
}

private void BilgeButton_MouseUp(object sender, MouseEventArgs e) {
if ((e.Button & MouseButtons.Left) > 0) {
if (e.Button.HasFlag(MouseButtons.Left)) {
IsMouseDown = false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Forms/NetGraphForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void settings_Click(object sender, EventArgs e) {
}

private void trayIcon_MouseClick(object sender, MouseEventArgs e) {
if ((e.Button & MouseButtons.Left) > 0) {
if (e.Button.HasFlag(MouseButtons.Left)) {
ToggleWindowVisibility();
}
}
Expand All @@ -241,14 +241,14 @@ private void NetGraphForm_Resize(object sender, EventArgs e) {

private void NetGraphForm_MouseDown(object sender, MouseEventArgs e) {
// Record drag start location.
if ((e.Button & MouseButtons.Left) > 0) {
if (e.Button.HasFlag(MouseButtons.Left)) {
dragPoint = e.Location;
}
}

private void NetGraphForm_MouseMove(object sender, MouseEventArgs e) {
// Drag form.
if ((e.Button & MouseButtons.Left) > 0) {
if (e.Button.HasFlag(MouseButtons.Left)) {
var container = Screen.FromRectangle(Bounds).WorkingArea;
var x = Location.X + e.X - dragPoint.X;
var y = Location.Y + e.Y - dragPoint.Y;
Expand Down

0 comments on commit cfea35c

Please sign in to comment.