forked from Ylianst/MeshCentralRouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKVMResizeControl.cs
More file actions
138 lines (118 loc) · 5.27 KB
/
Copy pathKVMResizeControl.cs
File metadata and controls
138 lines (118 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Copyright 2009-2021 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Windows.Forms;
using System.ComponentModel;
namespace MeshCentralRouter
{
public partial class KVMResizeControl : UserControl
{
private bool zoomtofit = false;
public KVMControl KVM { get { return kvmControl; } }
public bool ZoomToFit { get { return zoomtofit; } set { zoomtofit = value; CenterKvmControl(false); } }
[Category("Action")]
[Description("Fires when the connection state changes.")]
public event EventHandler StateChanged;
[Category("Action")]
[Description("Fires when the display list is received.")]
public event EventHandler DisplaysReceived;
public KVMResizeControl()
{
InitializeComponent();
vScrollBar.LargeChange = 100;
vScrollBar.SmallChange = 10;
hScrollBar.LargeChange = 100;
hScrollBar.SmallChange = 10;
//KVM.StateChanged += new EventHandler(KVM_StateChanged);
KVM.DisplaysReceived += new EventHandler(KVM_DisplaysReceived);
CenterKvmControl(false);
}
void KVM_StateChanged(object sender, EventArgs e)
{
if (InvokeRequired) { Invoke(new EventHandler(KVM_StateChanged), sender, e); return; }
CenterKvmControl(false);
kvmControl.Visible = false;
//kvmControl.Visible = (kvmControl.State == KVMControl.ConnectState.Connected);
if (StateChanged != null) StateChanged(this, e);
}
void KVM_DisplaysReceived(object sender, EventArgs e)
{
if (InvokeRequired) { Invoke(new EventHandler(KVM_DisplaysReceived), sender, e); return; }
if (DisplaysReceived != null) DisplaysReceived(this, e);
}
public void CenterKvmControl(bool forceRefresh)
{
int w = clientPanel.Width;
int h = clientPanel.Height;
int l = 0;
int t = 0;
bool invalidate = true;
if (zoomtofit == false)
{
if (kvmControl.Width != kvmControl.DesktopWidth || kvmControl.Height != kvmControl.DesktopHeight || kvmControl.ScaleFactor != 1)
{
kvmControl.Size = new System.Drawing.Size(kvmControl.DesktopWidth, kvmControl.DesktopHeight);
kvmControl.ScaleFactor = 1;
invalidate = true;
}
hScrollBar.Visible = (w < kvmControl.DesktopWidth);
rightScrollPanel.Visible = vScrollBar.Visible = (h < kvmControl.DesktopHeight);
cornerBlockPanel.Visible = (hScrollBar.Visible & vScrollBar.Visible);
}
else
{
hScrollBar.Visible = false;
rightScrollPanel.Visible = false;
double sfx = (double)kvmControl.DesktopWidth / (double)Width;
double sfy = (double)kvmControl.DesktopHeight / (double)Height;
double sf = Math.Max(sfx, sfy);
sf = Math.Max(1, sf);
if ((kvmControl.ScaleFactor != sf) || (forceRefresh))
{
kvmControl.Size = new System.Drawing.Size((int)((double)kvmControl.DesktopWidth / sf), (int)((double)kvmControl.DesktopHeight / sf));
kvmControl.ScaleFactor = sf;
invalidate = true;
}
}
if (w < kvmControl.Width) { hScrollBar.Maximum = (kvmControl.Width - w) + 100; } else { l = (w - kvmControl.Width) / 2; }
if (h < kvmControl.Height) { vScrollBar.Maximum = (kvmControl.Height - h) + 100; } else { t = (h - kvmControl.Height) / 2; }
if (vScrollBar.Visible) { kvmControl.Top = 0 - vScrollBar.Value; } else { kvmControl.Top = t; }
if (hScrollBar.Visible) { kvmControl.Left = 0 - hScrollBar.Value; } else { kvmControl.Left = l; }
if (invalidate) kvmControl.Invalidate();
}
private void kvmControl_Resize(object sender, EventArgs e)
{
CenterKvmControl(false);
}
private void ResizeKVMControl_Resize(object sender, EventArgs e)
{
CenterKvmControl(false);
}
private void vScrollBar_ValueChanged(object sender, EventArgs e)
{
kvmControl.Top = -vScrollBar.Value;
}
private void hScrollBar_ValueChanged(object sender, EventArgs e)
{
kvmControl.Left = -hScrollBar.Value;
}
private void kvmControl_DesktopSizeChanged(object sender, EventArgs e)
{
CenterKvmControl(true);
}
public void MouseWheelEx(object sender, MouseEventArgs e)
{
//if (KVMControl.WPF) kvmControl.SendMouseWheel(e, 0);
}
}
}