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

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

Public Sub DialogResultCallback(ByVal result As DialogResult) Implements _

IModelessDialogCallback.DialogResultCallback

MessageBox.Show(("dialog returned: " + IIf(result = DialogResult.OK, "OK", "Cancel")))

Me.Enabled = True

counter += 1

Me.bShow.Text = String.Format("Show Dialog: {0}", counter)

End Sub 'DialogResultCallback

Public Shared Sub Main()

Application.Run(New Test)

End Sub 'Main

End Class 'Test

Public Class ModelessDialog

Inherits Form

Private myParent As IModelessDialogCallback

Private bOK, bCancel As Button

Public Sub New(parent As IModelessDialogCallback)

Me.myParent = parent

Me.Text = "Modeless Dialog"

Me.bOK = New Button()

Me.bOK.Parent = Me

Me.bOK.Bounds = New Rectangle(10, 10, 150, 30)

Me.bOK.Text = "OK"

AddHandler Me.bOK.Click, AddressOf Me._Click

Me.bCancel = New Button()

Me.bCancel.Parent = Me

Me.bCancel.Bounds = New Rectangle(10, 50, 150, 30)

Me.bCancel.Text = "Cancel"

AddHandler Me.bCancel.Click, AddressOf Me._Click

End Sub 'New

Private Sub _Click(o As Object, e As EventArgs)

Me.Hide()

Me.myParent.DialogResultCallback(IIf(o Is Me.bOK, DialogResult.OK, DialogResult.Cancel))

End Sub '_Click

Protected Overrides Sub OnClosing(e As CancelEventArgs)

e.Cancel = True

Me.Hide()

Me.myParent.DialogResultCallback(DialogResult.Cancel)

End Sub 'OnClosing

End Class 'ModelessDialog

7.40. How do I round floating point numbers efficiently?

There are two primary methods for rounding numbers:

Convert.ToInt32

Cast or Fix (C# or VB) Convert.ToInt32 automatically handles rounding, where remainders of .5 and greater cause the number to be rounded up. Casting or using Fix requires adding .5 to the number to ensure that it will round properly, as these methods simply remove the remainder.

Profiling on the emulator and a Compaq iPAQ H3600 series device yielded the following results for 1 million operations of each method, where num is a float set to 3.6F:

Emulator

iPAQ

Operation

Debug (ms)

Release (ms)

Debug (ms)

Release (ms)

C#: Convert.ToInt32(num)

1321

1109

6264

6283

第一頁    上一頁    第72頁/共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- 王朝網路 版權所有 導航