微软.net精简框架常见问题及回答(中文版)(16)

王朝c#·作者佚名  2006-01-09
宽屏版  字体: |||超大  

'VB

Public Function GetNextControl(ByVal ctl As Control, _

ByVal forward As Boolean) As Control

Dim curIndex As Integer = Me.Controls.IndexOf(ctl)

If forward Then

If curIndex < Me.Controls.Count Then

curIndex += 1

Else

curIndex = 0

End If

Else

If curIndex > 0 Then

curIndex -= 1

Else

curIndex = Me.Controls.Count - 1

End If

End If

Return Me.Controls(curIndex)

End Function 'GetNextControl

5.36. How do I get notified when the user clicks on a treeview node?

TreeView does not support the Click event, however, a workaround is to use the AfterSelect event instead.

5.37. How do I set the title of a fullscreen multiline edit control window?

This is not supported by the current version of the .NET Compact Framework.

5.38. Why don' I see the validItem selected when I set ComboBox.SelectedValue to validItemInCollection?

Setting the SelectedValue property only works if the control is databound.

5.39. How do I detect the location where a 'tap & hold' occurred to bring up a context menu on my custom control?

Handle the ContextMenu.Popup event, and then query the current mouse coordinates using 'Control.MousePosition'.

5.40. Why doesn't the scrollbar value ever get set to the maximum value?

Similar to the NumericUpDown control, the maximum achievable value is the first empty row above the thumb. More specifically, from the editor properties, this equates to:

Maximum - (LargeChange + 1).

5.41. How do I tab out of a custom control to the previous control?

Call this.Parent.Controls(this.Parent.GetChildIndex(customcontrol) - 1).Focus() in the KeyDown event handler when a Keys.Up key is detected.

5.42. How do I add Toolbar buttons with transparency?

Icons support transparency, however, there is a known bug in Visual Studio .NET 2003 designer that creates incorrect code and makes icons non-transparent. A work around is to add an icon file to the ImageList outside of InitializeComponent and add the icon files to the project as content or embedded resources. The following code demonstrates this: //C#

using System.Drawing;

using System.IO;

using System.Reflection;

// Loaded as content example

private void Form1_Load(object sender, System.EventArgs e)

{

this.imageList1.Images.Add(new Icon(File.Open("fullFileName.ico",

FileMode.Open)));

this.toolBar1.Buttons[0].ImageIndex = 0;

}

// Loaded as a resource example

private void Form1_Load(object sender, System.EventArgs e)

{

this.imageList1.Images.Add(new

Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream(

".filename.ico")));

this.toolBar1.Buttons[0].ImageIndex = 0;

}

'VB

Imports System.Drawing

Imports System.IO

Imports System.Reflection

' Loaded as content example

Private Sub Form1_Load1(ByVal sender As Object, ByVal e As System.EventArgs)

Me.imageList1.Images.Add(New Icon(File.Open("fullFileName.ico", _

FileMode.Open)))

Me.toolBar1.Buttons(0).ImageIndex = 0

End Sub 'Form1_Load1

' Loaded as a resource example

Private Sub Form1_Load2(ByVal sender As Object, ByVal e As System.EventArgs)

Me.imageList1.Images.Add(New _

Icon([Assembly].GetExecutingAssembly().GetManifestResourceStream( _

".filename.ico")))

Me.toolBar1.Buttons(0).ImageIndex = 0

End Sub 'Form1_Load2

第一页    上一页    第16页/共78页    下一页    最后页
第01页 第02页 第03页 第04页 第05页 第06页 第07页 第08页 第09页 第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页 
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有