翻譯|使用教程|編輯:黃竹雯|2018-10-23 15:21:00.000|閱讀 522 次
概述:本文的分步指南向我們的甘特圖組件VARCHART XGantt用戶展示了如何設(shè)計清晰排列的工具提示。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
VARCHART XGantt是一個交互式的甘特圖控件,其模塊化的設(shè)計讓您可以創(chuàng)建滿足您和您的客戶所需求的應(yīng)用程序(我們領(lǐng)先的甘特圖控件VARCHART XGantt可用于.NET,ActiveX和ASP.NET應(yīng)用程序。)。VARCHART XGantt可以快速、簡單地集成到您的應(yīng)用程序中,幫助您識別性能瓶頸、避免延遲以及高效利用資源,使復(fù)雜數(shù)據(jù)變得更加容易理解。
甘特圖以時間軸可視化任務(wù),資源或能力,從而為規(guī)劃者提供最佳概覽。在設(shè)計時,應(yīng)牢記直接顯示對規(guī)劃者至關(guān)重要的信息,以便他能夠快速識別規(guī)劃沖突并進(jìn)行干預(yù)。顯示太多信息可能會危及清晰度。這就是為什么工具提示(tooltip)是僅在需要時顯示重要數(shù)據(jù)的好方法。甘特圖的真實情況也適用于工具提示:必須快速感知信息,這意味著必須以明確排序和排列的方式呈現(xiàn)信息。本分步指南向我們的甘特圖組件VARCHART XGantt用戶展示了如何設(shè)計清晰排列的工具提示。
VARCHART XGantt中包含的工具提示的設(shè)計選項受到限制:

這就是工具提示看起來像你繞過有限的設(shè)計選項,只需很少的編程工作:

首先,在VARCHART XGantt中停用VcToolTipTextSupplying事件:

然后在Visual Studio解決方案中創(chuàng)建一個新的表單TooltipWindow。在含有XGantt形式的構(gòu)造中,TooltipWindow得到由調(diào)用配置SetTooltipWindowAttributes方法。此方法如下所示:
TooltipWindow _ttw;
private void SetTooltipWindowAttributes()
{
_ttw = new TooltipWindow(vcGantt1);
//Settings for the Tooltip window:
_ttw.StartPosition = FormStartPosition.Manual;
_ttw.AutoScaleMode = AutoScaleMode.Font;
_ttw.AutoSize = true;
_ttw.AutoSizeMode = AutoSizeMode.GrowAndShrink;
_ttw.ControlBox = false;
_ttw.FormBorderStyle = FormBorderStyle.None;
_ttw.MaximizeBox = false;
_ttw.MinimizeBox = false;
_ttw.ShowIcon = false;
_ttw.ShowInTaskbar = false;
_ttw.TopMost = true;
}
現(xiàn)在在TooltipWindow上放置一個DataGridView 并將其命名為TTDataGrid。在DataGridView 的“ 編輯列”對話框中創(chuàng)建三列:

在TooltipWindow的構(gòu)造函數(shù)中,調(diào)用SetDataGridAttributes方法并通過此方法配置TTDataGrid。該方法如下所示:
private void SetDataGridAttributes()
{
//General settings for the data grid:
TTDataGrid.AllowUserToAddRows = false;
TTDataGrid.AllowUserToDeleteRows = false;
TTDataGrid.AllowUserToResizeColumns = false;
TTDataGrid.AllowUserToResizeRows = false;
TTDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
TTDataGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
TTDataGrid.ColumnHeadersVisible = false;
TTDataGrid.ReadOnly = true;
TTDataGrid.RowHeadersVisible = false;
TTDataGrid.ScrollBars = ScrollBars.None;
TTDataGrid.ShowCellToolTips = false;
TTDataGrid.RowTemplate.DefaultCellStyle.BackColor = Color.FromArgb(255, 240, 240, 240);
TTDataGrid.RowTemplate.DefaultCellStyle.ForeColor = Color.Black;
TTDataGrid.RowTemplate.DefaultCellStyle.SelectionBackColor = Color.FromArgb(255, 240, 240, 240);
TTDataGrid.RowTemplate.DefaultCellStyle.SelectionForeColor = Color.Black;
//Column 0:
DataGridViewImageColumn dgvic = (DataGridViewImageColumn)TTDataGrid.Columns[0];
dgvic.ImageLayout = DataGridViewImageCellLayout.Zoom;
dgvic.ReadOnly = true;
dgvic.Resizable = DataGridViewTriState.True;
dgvic.DefaultCellStyle.NullValue = null;
dgvic.DefaultCellStyle.SelectionBackColor = Color.FromArgb(255, 240, 240, 240);
dgvic.DefaultCellStyle.SelectionForeColor = Color.Black;
//Column 1:
DataGridViewColumn dgvc = TTDataGrid.Columns[1];
dgvc.ReadOnly = true;
dgvc.Resizable = DataGridViewTriState.True;
dgvc.SortMode = DataGridViewColumnSortMode.NotSortable;
//Column 2:
dgvc = TTDataGrid.Columns[2];
dgvc.ReadOnly = true;
dgvc.Resizable = DataGridViewTriState.True;
dgvc.SortMode = DataGridViewColumnSortMode.NotSortable;
}
將鼠標(biāo)移到VARCHART XGantt上會不斷觸發(fā)VcGantt_MouseMove事件。在這種情況下,首先要通過VcGantt.IdentifyObjectAt方法識別鼠標(biāo)光標(biāo)當(dāng)前懸停的對象類型。
如果鼠標(biāo)光標(biāo)懸停在節(jié)點上(對象類型為vcObjTypeNodeInDiagram),則會啟動一個計時器,使TooltipWindow可見。如果鼠標(biāo)光標(biāo)遠(yuǎn)離節(jié)點,則TooltipWindow將再次切換為不可見。
這需要通過以下代碼行實現(xiàn):
bool _isVisible = false;
private void TooltipWindow_VisibleChanged(object sender, EventArgs e)
{
VcNode node = _gantt.GetNodeByID(_nodeID);
_isVisible = !_isVisible;
if (_isVisible)
{
FillDataGrid(node);
ResizeDataGrid();
}
else
TTDataGrid.Rows.Clear();
}
private void FillDataGrid(VcNode node)
{
object[] rowValues = new object[TTDataGrid.Columns.Count];
//Fill data grid
for (short i = 0; i < _dtfc.Count; i++)
{
rowValues[1] = _dtfc.DataTableFieldByIndex(i).Name + ":";
rowValues[2] = node.get_DataField(i).ToString();
TTDataGrid.Rows.Add(rowValues);
}
//Set attributes for cell(s) which match certain criteria
DataGridViewCellStyle redCellStyle = new DataGridViewCellStyle();
redCellStyle.ForeColor = Color.Red;
redCellStyle.SelectionForeColor = Color.Red;
redCellStyle.Font = new Font("Microsoft Sans Serif", 8, FontStyle.Bold);
if (Convert.ToInt32(node.get_DataField(4)) >= 10) // 4: Duration
{
TTDataGrid[0, 4].Value = Enhanced_Tooltip.Properties.Resources.Warning;
TTDataGrid[2, 4].Style = redCellStyle;
}
}
private void ResizeDataGrid()
{
int dataGridWidth = 0;
int dataGridHeight = 0;
//Resize width of data grid
for (int i = 0; i < TTDataGrid.Columns.Count; i++)
dataGridWidth += TTDataGrid.Columns[i].Width;
TTDataGrid.Width = dataGridWidth;
//Resize height of data grid
for (int i = 0; i < TTDataGrid.Rows.Count; i++)
dataGridHeight += TTDataGrid.Rows[i].Height;
TTDataGrid.Height = dataGridHeight;
}
在FillDataGrid方法中,VARCHART XGantt的數(shù)據(jù)定義的所有數(shù)據(jù)字段都示例性地加載到DataGrid中。此外,所有操作持續(xù)時間大于或等于10,都顯示為紅色,并在DataGrid的第一列中用黃色感嘆號表示。當(dāng)然,所有這些都可以根據(jù)需要進(jìn)行定制。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn