本文整理汇总了C#中System.Windows.Forms.TabControl.GetTabRect方法的典型用法代码示例。如果您正苦于以下问题:C# TabControl.GetTabRect方法的具体用法?C# TabControl.GetTabRect怎么用?C# TabControl.GetTabRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TabControl
的用法示例。
在下文中一共展示了TabControl.GetTabRect方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawTabControlTabs
private void DrawTabControlTabs(TabControl tabControl, DrawItemEventArgs e, ImageList images)
{
// Get the bounding end of tab strip rectangles.
var tabstripEndRect = tabControl.GetTabRect(tabControl.TabPages.Count - 1);
var tabstripEndRectF = new RectangleF(tabstripEndRect.X + tabstripEndRect.Width, tabstripEndRect.Y - 5,
tabControl.Width - (tabstripEndRect.X + tabstripEndRect.Width), tabstripEndRect.Height + 5);
var leftVerticalLineRect = new RectangleF(2, tabstripEndRect.Y + tabstripEndRect.Height + 2, 2, tabControl.TabPages[tabControl.SelectedIndex].Height + 2);
var rightVerticalLineRect = new RectangleF(tabControl.TabPages[tabControl.SelectedIndex].Width + 4, tabstripEndRect.Y + tabstripEndRect.Height + 2, 2, tabControl.TabPages[tabControl.SelectedIndex].Height + 2);
var bottomHorizontalLineRect = new RectangleF(2, tabstripEndRect.Y + tabstripEndRect.Height + tabControl.TabPages[tabControl.SelectedIndex].Height + 2, tabControl.TabPages[tabControl.SelectedIndex].Width + 4, 2);
RectangleF leftVerticalBarNearFirstTab = new Rectangle(0, 0, 2, tabstripEndRect.Height + 2);
// First, do the end of the tab strip.
// If we have an image use it.
if (tabControl.Parent.BackgroundImage != null)
{
var src = new RectangleF(tabstripEndRectF.X + tabControl.Left, tabstripEndRectF.Y + tabControl.Top, tabstripEndRectF.Width, tabstripEndRectF.Height);
e.Graphics.DrawImage(tabControl.Parent.BackgroundImage, tabstripEndRectF, src, GraphicsUnit.Pixel);
}
// If we have no image, use the background color.
else
{
using (var backBrush = new SolidBrush(tabControl.Parent.BackColor))
{
e.Graphics.FillRectangle(backBrush, tabstripEndRectF);
e.Graphics.FillRectangle(backBrush, leftVerticalLineRect);
e.Graphics.FillRectangle(backBrush, rightVerticalLineRect);
e.Graphics.FillRectangle(backBrush, bottomHorizontalLineRect);
if (mainTabControl.SelectedIndex != 0)
{
e.Graphics.FillRectangle(backBrush, leftVerticalBarNearFirstTab);
}
}
}
// Set up the page and the various pieces.
var page = tabControl.TabPages[e.Index];
using (var backBrush = new SolidBrush(page.BackColor))
{
using (var foreBrush = new SolidBrush(page.ForeColor))
{
var tabName = page.Text;
// Set up the offset for an icon, the bounding rectangle and image size and then fill the background.
var iconOffset = 0;
Rectangle tabBackgroundRect;
if (e.Index == mainTabControl.SelectedIndex)
{
tabBackgroundRect = e.Bounds;
e.Graphics.FillRectangle(backBrush, tabBackgroundRect);
}
else
{
tabBackgroundRect = new Rectangle(e.Bounds.X, e.Bounds.Y - 2, e.Bounds.Width, e.Bounds.Height + 4);
e.Graphics.FillRectangle(backBrush, tabBackgroundRect);
var rect = new Rectangle(e.Bounds.X - 2, e.Bounds.Y - 2, 1, 2);
e.Graphics.FillRectangle(backBrush, rect);
rect = new Rectangle(e.Bounds.X - 1, e.Bounds.Y - 2, 1, 2);
e.Graphics.FillRectangle(backBrush, rect);
rect = new Rectangle(e.Bounds.X + e.Bounds.Width, e.Bounds.Y - 2, 1, 2);
e.Graphics.FillRectangle(backBrush, rect);
rect = new Rectangle(e.Bounds.X + e.Bounds.Width + 1, e.Bounds.Y - 2, 1, 2);
e.Graphics.FillRectangle(backBrush, rect);
}
// If we have images, process them.
if (images != null)
{
// Get sice and image.
var size = images.ImageSize;
Image icon = null;
if (page.ImageIndex > -1)
icon = images.Images[page.ImageIndex];
else if (page.ImageKey != "")
icon = images.Images[page.ImageKey];
// If there is an image, use it.
if (icon != null)
{
var startPoint =
new Point(tabBackgroundRect.X + 2 + ((tabBackgroundRect.Height - size.Height) / 2),
tabBackgroundRect.Y + 2 + ((tabBackgroundRect.Height - size.Height) / 2));
e.Graphics.DrawImage(icon, new Rectangle(startPoint, size));
iconOffset = size.Width + 4;
}
}
// Draw out the label.
var labelRect = new Rectangle(tabBackgroundRect.X + iconOffset, tabBackgroundRect.Y + 5,
tabBackgroundRect.Width - iconOffset, tabBackgroundRect.Height - 3);
using (var sf = new StringFormat { Alignment = StringAlignment.Center })
{
e.Graphics.DrawString(tabName, new Font(e.Font.FontFamily, 8.25F, e.Font.Style), foreBrush, labelRect, sf);
}
}
}
}
示例2: tabProc_MouseDown
public static void tabProc_MouseDown(int SelectedProcTab,ODGrid gridProg,TabControl tabProc,Size ClientSize,MouseEventArgs e) {
if(Programs.UsingOrion) {
return;//tabs never minimize
}
//selected tab will have changed, so we need to test the original selected tab:
Rectangle rect=tabProc.GetTabRect(SelectedProcTab);
if(rect.Contains(e.X,e.Y) && tabProc.Height>27) {//clicked on the already selected tab which was maximized
tabProc.Height=27;
tabProc.Refresh();
gridProg.Location=new Point(tabProc.Left,tabProc.Bottom+1);
gridProg.Height=ClientSize.Height-gridProg.Location.Y-2;
}
else if(tabProc.Height==27) {//clicked on a minimized tab
tabProc.Height=259;
tabProc.Refresh();
gridProg.Location=new Point(tabProc.Left,tabProc.Bottom+1);
gridProg.Height=ClientSize.Height-gridProg.Location.Y-2;
}
else {//clicked on a new tab
//height will have already been set, so do nothing
}
SelectedProcTab=tabProc.SelectedIndex;
}
示例3: GetTabRectTest
public void GetTabRectTest ()
{
TabControl myTabControl = new TabControl ();
TabPage myTabPage = new TabPage();
myTabControl.Controls.Add(myTabPage);
myTabPage.TabIndex = 0;
Rectangle myTabRect = myTabControl.GetTabRect (0);
Assert.AreEqual (2, myTabRect.X, "#GetT1");
Assert.AreEqual (2, myTabRect.Y, "#GetT2");
Assert.AreEqual (42, myTabRect.Width, "#GetT3");
// It is environment dependent
//Assert.AreEqual (18, myTabRect.Height, "#GetT4");
}
示例4: ux_tabcontrolMouseDownEvent
public void ux_tabcontrolMouseDownEvent(TabControl ux_tabcontrolDataview, MouseEventArgs e)
{
int clickedTabPage = ux_tabcontrolDataview.SelectedIndex;
// Attempt to find the tabpage that was clicked...
for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++)
{
if (ux_tabcontrolDataview.GetTabRect(i).Contains(e.Location)) clickedTabPage = i; //MessageBox.Show(ux_tabcontrolDataview.TabPages[i].Text + " : " + e.Location.ToString());
}
if (e.Button == MouseButtons.Left)
{
// Begin tabpage drag and drop move (if the clicked tab is not
// the "ux_tabpageDataviewNewTab" tabpage - which is use to add new dataviews)...
if (ux_tabcontrolDataview.TabPages[clickedTabPage] != ux_tabcontrolDataview.TabPages["ux_tabpageDataviewNewTab"])
{
ux_tabcontrolDataview.DoDragDrop(ux_tabcontrolDataview.TabPages[clickedTabPage], DragDropEffects.Move);
}
}
else if (e.Button == MouseButtons.Right)
{
// Make the right clicked tabpage the selected tabpage for the control...
ux_tabcontrolDataview.SelectTab(clickedTabPage);
}
}
示例5: TabAtPoint
private TabPage TabAtPoint(TabControl tabCtrl, Point location)
{
for (int i = 0; i < tabCtrl.TabCount; i++)
{
Rectangle r = tabCtrl.GetTabRect(i);
if (r.Contains(location))
{
return tabCtrl.TabPages[i];
}
}
return null;
}
示例6: ux_tabcontrolDragDropEvent
public void ux_tabcontrolDragDropEvent(TabControl ux_tabcontrolDataview, DragEventArgs e)
{
if (e.AllowedEffect == e.Effect)
{
// Convert the mouse coordinates from screen to client...
System.Drawing.Point ptClientCoord = ux_tabcontrolDataview.PointToClient(new System.Drawing.Point(e.X, e.Y));
int destinationTabPageIndex = -1;
int originalTabPageIndex = -1;
// Attempt to find where the tabpage should be dropped...
for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++)
{
//if (ux_tabcontrolDataview.TabPages[i] == e.Data.GetData(typeof(TabPage))) originalTabPageIndex = i;
if (ux_tabcontrolDataview.TabPages[i] == e.Data.GetData("System.Windows.Forms.TabPage")) originalTabPageIndex = i;
if (ux_tabcontrolDataview.GetTabRect(i).Contains(ptClientCoord)) destinationTabPageIndex = i;
}
// Now create a copy of the tabpage that is being moved so that
// you can remove the orginal and insert the copy at the right spot...
TabPage newTabPage = new TabPage();
//newTabPage.Text = ((TabPage)e.Data.GetData(typeof(TabPage))).Text;
newTabPage.Text = ((TabPage)e.Data.GetData("System.Windows.Forms.TabPage")).Text;
//newTabPage.Tag = ((TabPage)e.Data.GetData(typeof(TabPage))).Tag;
newTabPage.Tag = ((TabPage)e.Data.GetData("System.Windows.Forms.TabPage")).Tag;
ux_tabcontrolDataview.TabPages.Insert(destinationTabPageIndex, newTabPage);
ux_tabcontrolDataview.SelectTab(destinationTabPageIndex);
if (originalTabPageIndex < destinationTabPageIndex)
{
ux_tabcontrolDataview.TabPages.RemoveAt(originalTabPageIndex);
}
else
{
ux_tabcontrolDataview.TabPages.RemoveAt(originalTabPageIndex + 1);
}
}
}
示例7: ux_tabcontrolDragOverEvent
public void ux_tabcontrolDragOverEvent(TabControl ux_tabcontrolDataview, DragEventArgs e)
{
// Convert the mouse coordinates from screen to client...
System.Drawing.Point ptClientCoord = ux_tabcontrolDataview.PointToClient(new System.Drawing.Point(e.X, e.Y));
//int destinationTabPage = ux_tabcontrolDataview.TabPages.IndexOf((TabPage)e.Data.GetData(typeof(TabPage)));
if (e.Data.GetDataPresent("System.Windows.Forms.TabPage"))
{
int destinationTabPage = ux_tabcontrolDataview.TabPages.IndexOf((TabPage)e.Data.GetData("System.Windows.Forms.TabPage"));
// Attempt to find the tabpage that is being dragged over...
for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++)
{
if (ux_tabcontrolDataview.GetTabRect(i).Contains(ptClientCoord)) destinationTabPage = i;
}
////if (e.Data.GetDataPresent(typeof(TabPage)) &&
//if (e.Data.GetDataPresent("System.Windows.Forms.TabPage") &&
////ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData(typeof(TabPage)) /* &&
//ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData("System.Windows.Forms.TabPage") /* &&
// destinationTabPage != ux_tabcontrolDataview.TabPages.IndexOfKey("ux_tabpageDataviewNewTab")*/
// )
if (ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData(typeof(TabPage)))
{
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
示例8: DrawTabControl
public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab )
{
// Do we need to fill the back color? It can't be changed...
dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area );
Rectangle panel_rect = TabControlGetPanelRect( tab );
if ( tab.Appearance == TabAppearance.Normal )
{
CPDrawBorder( dc, panel_rect, BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid,
BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid );
}
if ( tab.Alignment == TabAlignment.Top )
{
for ( int r = tab.TabPages.Count; r > 0; r-- )
{
for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
{
if ( i == tab.SelectedIndex )
continue;
if ( r != tab.TabPages[ i ].Row )
continue;
Rectangle rect = tab.GetTabRect( i );
if ( !rect.IntersectsWith( area ) )
continue;
DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
}
}
}
else
{
for ( int r = 0; r < tab.TabPages.Count; r++ )
{
for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
{
if ( i == tab.SelectedIndex )
continue;
if ( r != tab.TabPages[ i ].Row )
continue;
Rectangle rect = tab.GetTabRect( i );
if ( !rect.IntersectsWith( area ) )
continue;
DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
}
}
}
if ( tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos )
{
Rectangle rect = tab.GetTabRect( tab.SelectedIndex );
if ( rect.IntersectsWith( area ) )
DrawTab( dc, tab.TabPages[ tab.SelectedIndex ], tab, rect, true );
}
if ( tab.ShowSlider )
{
Rectangle right = TabControlGetRightScrollRect( tab );
Rectangle left = TabControlGetLeftScrollRect( tab );
CPDrawScrollButton( dc, right, ScrollButton.Right, tab.RightSliderState );
CPDrawScrollButton( dc, left, ScrollButton.Left, tab.LeftSliderState );
}
}
示例9: Draw
public virtual void Draw (Graphics dc, Rectangle area, TabControl tab)
{
DrawBackground (dc, area, tab);
int start = 0;
int end = tab.TabPages.Count;
int delta = 1;
if (tab.Alignment == TabAlignment.Top) {
start = end;
end = 0;
delta = -1;
}
if (tab.SizeMode == TabSizeMode.Fixed)
defaultFormatting.Alignment = StringAlignment.Center;
else
defaultFormatting.Alignment = StringAlignment.Near;
int counter = start;
for (; counter != end; counter += delta) {
for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
if (i == tab.SelectedIndex)
continue;
if (counter != tab.TabPages[i].Row)
continue;
Rectangle rect = tab.GetTabRect (i);
if (!rect.IntersectsWith (area))
continue;
DrawTab (dc, tab.TabPages[i], tab, rect, false);
}
}
if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
if (rect.IntersectsWith (area))
DrawTab (dc, tab.TabPages[tab.SelectedIndex], tab, rect, true);
}
if (tab.ShowSlider) {
Rectangle right = GetRightScrollRect (tab);
Rectangle left = GetLeftScrollRect (tab);
DrawScrollButton (dc, right, area, ScrollButton.Right, tab.RightSliderState);
DrawScrollButton (dc, left, area, ScrollButton.Left, tab.LeftSliderState);
}
}
示例10: DrawTabControl
// FIXME: regions near the borders don't get filled with the correct backcolor
// TODO: TabAlignment.Left and TabAlignment.Bottom
public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab ) {
if (tab.Parent != null)
dc.FillRectangle( ResPool.GetSolidBrush( tab.Parent.BackColor ), area );
else
dc.FillRectangle( ResPool.GetSolidBrush( tab.BackColor ), area );
Rectangle panel_rect = TabControlGetPanelRect( tab );
if ( tab.Appearance == TabAppearance.Normal ) {
switch ( tab.Alignment ) {
case TabAlignment.Top:
// inner border...
Pen pen = ResPool.GetPen( Color.White );
dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top, panel_rect.Left + 1, panel_rect.Bottom - 1 );
dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top , panel_rect.Right - 2, panel_rect.Top );
pen = ResPool.GetPen( tab_inner_border_color );
dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
// border
pen = ResPool.GetPen( tab_border_color );
dc.DrawLine( pen, panel_rect.Left, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Top - 1 );
dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Bottom - 2 );
dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom - 2, panel_rect.Right - 3, panel_rect.Bottom );
dc.DrawLine( pen, panel_rect.Right - 3, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top - 1 );
break;
// FIXME: the size of the tab page is to big to draw the upper inner white border
case TabAlignment.Right:
// inner border...
pen = ResPool.GetPen( Color.White );
dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top + 1, panel_rect.Left + 1, panel_rect.Bottom - 1 );
dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top + 1 , panel_rect.Right - 2, panel_rect.Top + 1 );
pen = ResPool.GetPen( tab_inner_border_color );
dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
// border
pen = ResPool.GetPen( tab_border_color );
dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top, panel_rect.Right - 1, panel_rect.Top );
dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top, panel_rect.Right - 1, panel_rect.Bottom );
dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top + 2 );
dc.DrawLine( pen, panel_rect.Left, panel_rect.Top + 2, panel_rect.Left + 2, panel_rect.Top );
break;
}
}
if (tab.Alignment == TabAlignment.Top) {
for (int r = tab.TabPages.Count; r > 0; r--) {
for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
if (i == tab.SelectedIndex)
continue;
if (r != tab.TabPages [i].Row)
continue;
Rectangle rect = tab.GetTabRect (i);
if (!rect.IntersectsWith (area))
continue;
DrawTab (dc, tab.TabPages [i], tab, rect, false);
}
}
} else {
for (int r = 0; r < tab.TabPages.Count; r++) {
for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
if (i == tab.SelectedIndex)
continue;
if (r != tab.TabPages [i].Row)
continue;
Rectangle rect = tab.GetTabRect (i);
if (!rect.IntersectsWith (area))
continue;
DrawTab (dc, tab.TabPages [i], tab, rect, false);
}
}
}
if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
if (rect.IntersectsWith (area))
DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
}
if (tab.ShowSlider) {
Rectangle right = TabControlGetRightScrollRect (tab);
Rectangle left = TabControlGetLeftScrollRect (tab);
CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
}
}
示例11: getHoverTabIndex
private int getHoverTabIndex(TabControl tc)
{
for (int i = 0; i < tc.TabPages.Count; i++)
{
if (tc.GetTabRect(i).Contains(tc.PointToClient(Cursor.Position)))
return i;
}
return -1;
}
示例12: GetPageByPoint
private TabPage GetPageByPoint(TabControl tabControl, Point point)
{
for (int i = 0; i < tabControl.TabPages.Count; i++)
{
TabPage page = tabControl.TabPages[i];
if (tabControl.GetTabRect(i).Contains(point))
return page;
}
return null;
}