Welcome Guest!
 VB.NET Helper
 Previous Message All Messages Next Message 
VB .NET Helper Newsletter  Rod Stephens
 Nov 11, 2011 19:08 PST 

Just a quick newsletter this week, mostly to wish you a happy 11/11/11!

The math in the Apollonius Problem examples is pretty involved. If you
figure out how to eliminate the divide-by-zero in some cases, let me
know.
-----
John Mueller posted part 8 in his series describing the GrabAPicture
application. This installment talks about serialization. Take a look
when you have a chance.

http://blog.johnmuellerbooks.com/2011/11/04/exploring-the-grabapicture-application-part-8-.aspx

-----
Mike Doty mentioned Microsoft's "Fix it" solution center. It
automatically diagnoses and tries to fix common problems with Microsoft
products such as Windows, Internet Explorer, Windows Media Player, and
others.

http://support.microsoft.com/fixit
-----
Now available:
    Start Here! Fundamentals of Microsoft .NET Programming
    http://shop.oreilly.com/product/0790145330536.do

On sale at $7.99 for a limited time at:

    http://shop.oreilly.com/product/0790145330536.do

Also available:
    Start Here! Learn Microsoft Visual C# 2010
    By John Paul Mueller
    http://shop.oreilly.com/product/0790145319210.do

If you buy John's book, you will receive a coupon that lets you get my
book in electronic format for free (because it's supposed to supplement
the other books).
-----
Have a great week and thanks for subscribing!

Rod
RodSte-@vb-helper.com

Twitter feeds:
    VBHelper
    CSharpHelper
==========
==========

    VB.NET Contents:
1. New HowTo: Find circles that are tangent to three given circles in
Visual Basic .NET
2. New HowTo: Draw three circles and find circles that are tangent to
all three in Visual Basic .NET
3. New HowTo: Remove the X Close button from a form's system menu in
Visual Basic .NET
==========
++++++++++
      <VB.NET>
++++++++++
==========
1. New HowTo: Find circles that are tangent to three given circles in
Visual Basic .NET
http://www.vb-helper.com/howto_net_apollonius_problem.html
http://www.vb-helper.com/HowTo/howto_net_apollonius_problem.zip

(Picture at http://www.vb-helper.com/howto_net_apollonius_problem.png)

Given three objects that can be a point, line, or circle, you can try to
draw circles that are tangent to each. The case using three circles is
called Apollonius' Problem. Originally these problems were studied by
Euclid (ca. 300 BC) and Apollonius of Perga (ca. 262 BC - ca. 190 BC)
and they were solved geometrically with straight edge and compass.

This example solves Apollonius' Problem by finding solutions to the
three following equations algebraically.

    (X - X1)^2 + (Y - Y1)^2 = (R +/- R1)^2
    (X - X2)^2 + (Y - Y2)^2 = (R +/- R2)^2
    (X - X3)^2 + (Y - Y3)^2 = (R +/- R3)^2

Unfortunately solving the equations requires dividing by some terms that
may be zero and in those cases the solution doesn't work. In some cases
that's because some solutions are degenerate. For example, suppose the
three circles have the same radii and are all tangent to the X axis.
Then two of the tangent "circles" are actually lines, one along the X
axis and one parallel to the X axis on the other side of the circles.

In other cases the division by zero seems to be caused by the method for
solving the equations and real solutions do exist. This is a tricky
problem and I haven't yet found a solution. If you figure out how to
solve these equations without these problems, please let me know
(RodSte-@vb-helper.com).

For more discussion of the problem and how to solve the equations, see:

    - Wolfram MathWorld
(http://mathworld.wolfram.com/ApolloniusProblem.html)
    - Wikipedia
(http://en.wikipedia.org/wiki/Problem_of_Apollonius#Algebraic_solutions)
    - Rosetta Code (http://rosettacode.org/wiki/Problem_of_Apollonius)

See the code for details about how this program works.
==========
2. New HowTo: Draw three circles and find circles that are tangent to
all three in Visual Basic .NET
http://www.vb-helper.com/howto_net_apollonius_problem2.html
http://www.vb-helper.com/HowTo/howto_net_apollonius_problem2.zip

This example is similar to previous one "Find circles that are tangent
to three given circles in Visual Basic .NET" except it lets you click
and drag to draw the three given circles. It then finds the (up to) 8
tangent circles.

For more information see the previous example and the links it mentions.
==========
3. New HowTo: Remove the X Close button from a form's system menu in
Visual Basic .NET
http://www.vb-helper.com/howto_net_remove_close_x.html
http://www.vb-helper.com/HowTo/howto_net_remove_close_x.zip

Visual Basic doesn't have a built-in way to manipulate the system menu
that appears when you click the upper left corner of a form, but it's
not too hard to use API functions to remove some or all of those
buttons.

This example uses the following Imports statement:

Imports System.Runtime.InteropServices

This statement allows the program to use the DllImport statement to
import the User32.dll library methods in the following code.

' Declare User32 constants and methods.
Private Const MF_BYPOSITION As Integer = &H400

<DllImport("user32.dll", CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function GetSystemMenu(ByVal hWnd As IntPtr, ByVal
bRevert As Boolean) As IntPtr
End Function

<DllImport("user32.dll")> _
Public Shared Function GetMenuItemCount(ByVal hMenu As IntPtr) As Int32
End Function

<DllImport("user32.dll")> _
Public Shared Function RemoveMenu(ByVal hMenu As IntPtr, ByVal nPosition
As Int32, ByVal wFlags As Int32) As Int32
End Function

' Remove the X button.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
    Dim hMenu As IntPtr = GetSystemMenu(Me.Handle, False)
    Dim num_menu_items As Integer = GetMenuItemCount(hMenu)

    'For i As Integer = num_menu_items - 1 To 0 Step -1
    '    RemoveMenu(hMenu, i, MF_BYPOSITION)
    'Next i
    RemoveMenu(hMenu, num_menu_items - 1, MF_BYPOSITION)
    RemoveMenu(hMenu, num_menu_items - 2, MF_BYPOSITION)
End Sub

This code first defines the GetSystemMenu, GetMenuItemCount, and
RemoveMenu API functions. The form's Load event handler uses
GetSystemMenu to get the handle for the form's system menu. It then uses
GetMenuItemCount to see how many items the menu contains. It then calls
RemoveMenu twice to remove the Close menu item and the separator that
comes before it in the menu.

You can see in the picture that the X menu item and the separator before
it has been completely removed. If you look very closely, you can also
see that the X close button in the form's upper right corner is
disabled.

Notice that the code removes the menu's last item first and then removes
the second-to-last item second. If it tried to remove the second-to-last
item first, then the menu would have one fewer item when the code tried
to remove the last item so it wouldn't work. The code should only remove
items in positions that exist at the time.

If you remove all of the system's menu items, the user will not be able
to move, resize, or close the form, and the form's system menu will not
appear. However the system menu's symbol still appears in the form's
upper left corner, the cursor still changes to the resize cursor when
you hold it over the form's borders, and the minimize and maximize
buttons still work. All in all, this is pretty confusing to the user. If
you want to remove that menu completely, set the form's ControlBox
property to False instead.

Also note that none of these techniques prevent the user from closing
the form by pressing Alt+F4.
==========
Archives:
    http://www.topica.com/lists/VBHelper
    http://www.topica.com/lists/VB6Helper
    http://www.topica.com/lists/VBNetHelper

Twitter feeds:
    VBHelper
    CSharpHelper

Post questions at:
    http://www.topica.com/lists/VBHelperQA
	
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Developers
 Food & Drink
 Health & Fitness
 Internet
 Music
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Software
 Sports
 Travel & Leisure
 Women & Family

  Start Your Own List!
Email lists are great for debating issues or publishing your views.
Start a List Today!

© 2001 Topica Inc. TFMB
Concerned about privacy? Topica is TrustE certified.
See our Privacy Policy.