locked
Plz help me RRS feed

  • Question

  • hey I have a piece of code which gives fade effect to a form at load event
    But it works only with normal forms and doesnt work for the forms which gets loaded into a mdi parent form
    plz help me out 

    Here is the code:

    1) Create a class called "Fade.vb"

    and add code(wow my vb... I even don't know how to add a event..):

    Public Class Fade
        WithEvents Tin As New Timer()
        WithEvents Tout As New Timer()
        Public Event FadeInCompleted()
        Public Event FadeOutCompleted()

        Public Sub FadeIn(ByRef form As Windows.Forms.Form, ByVal Interval As Int32)
            Tin.Interval = Interval
            Tin.Start()
            Tin.Tag = form
        End Sub

        Public Sub FadeInTick() Handles Tin.Tick
            Dim F As Form = Tin.Tag
            If (F.Opacity <= 0) Then
                Tin.Stop()
                RaiseEvent FadeInCompleted()
            End If
            F.Opacity -= 0.01
        End Sub

        Public Sub FadeOut(ByRef form As Windows.Forms.Form, ByVal Interval As Int32)
            Tout.Interval = Interval
            Tout.Start()
            Tout.Tag = form
        End Sub

        Public Sub FadeOutTick() Handles Tout.Tick
            Dim F As Form = Tout.Tag
            If (F.Opacity >= 1) Then
                Tout.Stop()
                RaiseEvent FadeOutCompleted()
            End If
            F.Opacity += 0.01
        End Sub

    End Class
     

     

     

    2)

    OK and in your form

     

    Public Class Form1

        WithEvents F As New Fade()
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Opacity = 0
            F.FadeOut(Me, 10)
        End Sub

        Private Sub FadedOut() Handles F.FadeOutCompleted

        End Sub
    End Class

     

     

    3)

    All right Run! 
    Sunday, March 8, 2009 5:44 PM

Answers

  • Only top level windows can have their opacity set.  Do you have to use MDI children?  You might be able to fake something together using the SetParent API after your form has faded in.

    This works, but it might not suit your purpose:
    Public Class Form2 
     
        Public MyParent As Form 
     
        Private Declare Auto Function SetParent Lib "user32" Alias "SetParent" ( _ 
        ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr 
     
        WithEvents F As New Fade() 
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
            Me.Opacity = 0.0 
            F.FadeOut(Me, 10) 
        End Sub 
     
        Private Sub FadedOut() Handles F.FadeOutCompleted 
            SetParent(Me.Handle, MyParent.Handle) 
        End Sub 
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
     
        End Sub 
    End Class 


    Then when you create the form, you do this:
            Dim f As New Form2 
            f.MyParent = Me 
     
            f.Show() 








    Negative0 http://johnkoerner.com
    Sunday, March 8, 2009 6:20 PM
  • fireblade123 said:

    how shall i sense that a windows form was minimized either by using taskbar or by using standard windows controls
    also how shall i sense that it was restored from taskbar?


    Hi fireblade,

    1. You can handle the Form_SizeChanged event or Form_Resize event with the following code snippet to sense Form minimized and restored.

        Private Sub Form1_SizeChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.SizeChanged  
            If Me.WindowState = FormWindowState.Minimized Then 
                MessageBox.Show("Minimized")  
            ElseIf Me.WindowState = FormWindowState.Normal Then 
                MessageBox.Show("Restored")  
            End If 
        End Sub 

    2. Article: How to add Maximize, Minimize and Restore events for Form: WindowStateChanged
    http://www.cnblogs.com/zhouyinhui/archive/2007/01/12/619175.html



    Best regards,
    Martin Xie
    • Marked as answer by fireblade123 Monday, March 16, 2009 2:46 PM
    Monday, March 16, 2009 1:29 PM

All replies

  • Only top level windows can have their opacity set.  Do you have to use MDI children?  You might be able to fake something together using the SetParent API after your form has faded in.

    This works, but it might not suit your purpose:
    Public Class Form2 
     
        Public MyParent As Form 
     
        Private Declare Auto Function SetParent Lib "user32" Alias "SetParent" ( _ 
        ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr 
     
        WithEvents F As New Fade() 
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
            Me.Opacity = 0.0 
            F.FadeOut(Me, 10) 
        End Sub 
     
        Private Sub FadedOut() Handles F.FadeOutCompleted 
            SetParent(Me.Handle, MyParent.Handle) 
        End Sub 
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
     
        End Sub 
    End Class 


    Then when you create the form, you do this:
            Dim f As New Form2 
            f.MyParent = Me 
     
            f.Show() 








    Negative0 http://johnkoerner.com
    Sunday, March 8, 2009 6:20 PM
  • it is of no help
    anyway thanks
    Monday, March 9, 2009 6:18 PM
  • I believe you are a vb6 person. This is a .net forum.
    -Renee
    Monday, March 9, 2009 7:09 PM
  • hey i am a vb.net person
    Wednesday, March 11, 2009 6:42 PM
  • fireblade123 said:

    hey i am a vb.net person


    Hi fireblade,

    Welcome to MSDN forums!

    Negative is right.

    The Opacity only works with top-level windows. it won't work with an mdi child window.

    Document: http://msdn.microsoft.com/en-us/library/7aw8zc76.aspx

    The MDI child form is a standard Windows Form. As such, it has an Opacity property, which enables you to control the transparency of the form. However, the Opacity property was designed for top-level windows. Do not use it with MDI child forms, as painting problems can occur.

    Here is one threads discussing the similar issue to yours, please check it for some workaround.
    http://social.msdn.microsoft.com/forums/en-US/vblanguage/thread/bb929012-599f-4a36-bb17-d6eeb88ac56a/



    Best regards,
    Martin Xie
    Friday, March 13, 2009 10:32 AM
  • hi
     htanks for replying

    could any one answer for my this question

    how shall i sense that a windows form was minimized either by using taskbar or by using standard windows controls
    also how shall i sense that it was restored from taskbar??
    plz reply 
    Saturday, March 14, 2009 5:02 AM
  • fireblade123 said:

    how shall i sense that a windows form was minimized either by using taskbar or by using standard windows controls
    also how shall i sense that it was restored from taskbar?


    Hi fireblade,

    1. You can handle the Form_SizeChanged event or Form_Resize event with the following code snippet to sense Form minimized and restored.

        Private Sub Form1_SizeChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.SizeChanged  
            If Me.WindowState = FormWindowState.Minimized Then 
                MessageBox.Show("Minimized")  
            ElseIf Me.WindowState = FormWindowState.Normal Then 
                MessageBox.Show("Restored")  
            End If 
        End Sub 

    2. Article: How to add Maximize, Minimize and Restore events for Form: WindowStateChanged
    http://www.cnblogs.com/zhouyinhui/archive/2007/01/12/619175.html



    Best regards,
    Martin Xie
    • Marked as answer by fireblade123 Monday, March 16, 2009 2:46 PM
    Monday, March 16, 2009 1:29 PM
  • thank you Martin 

    I have 1 more question left which is my application requires a sql server ODBC driver to run
    I know the manual process for setting up the ODBC driver
    But i want that my application should itself be able to install the ODBC driver during its setup
    I should not need to do it manually

    I shall i implement this?

    plz reply...
    Monday, March 16, 2009 2:49 PM
  • fireblade123 said:

    I have 1 more question left which is my application requires a sql server ODBC driver to run
    I know the manual process for setting up the ODBC driver
    But i want that my application should itself be able to install the ODBC driver during its setup
    I should not need to do it manually


    Hi fireblade,

    You can add the ODBC .NET Data Provider as a custom prerequisite of the Setup Project.

    1. Please check this document for detailed instruction.
    Adding Custom Prerequisites
    http://msdn.microsoft.com/en-us/library/ms165429.aspx 
    Step 1. Creating Custom Packages 
    Step 2. Adding Packages to the Prerequisites Dialog Box
    The
    Prerequisites Dialog Box enables you to select which components your application requires before installation. Visual Studio includes several standard prerequisites. However, you can add other Microsoft or third-party components as prerequisites. To do so, you must author the product and package manifests.

    2. ODBC .NET Data Provider Download (odbc_net.msi)
    http://www.microsoft.com/downloads/details.aspx?FamilyID=6ccd8427-1017-4f33-a062-d165078e32b1&displaylang=en 


    By the way, the ClickOnce and Setup & Deployment Projects forum is dedicated to Project Deployment issues.



    Best regards,
    Martin Xie

    Wednesday, March 18, 2009 5:08 AM
  • thanks Martin for the reply

    but i am a beginner in xml
    i dont know how to use xml effectively
    i do not understand code from the artical of which u have provided link
    plz if u know to how to do this using third party software as a pre requisite then plz give a samlpe piece of code to refer

    thanks.... 
    Wednesday, March 18, 2009 9:14 AM
  • will u plz explian me what is the functionality of system.data.odbc namespace ?
    can the classes present it be used to solve my problem ?

    reply plz...
    Wednesday, March 18, 2009 9:30 AM
  •  
    fireblade123 said:

    will u plz explian me what is the functionality of system.data.odbc namespace?

    can the classes present it be used to solve my problem ?

    Hi fireblade,

    I recommend using System.Data.SqlClient namespace (instead of ODBC driver) to access SQL Server database,thus you don't need to make a custom prerequisite.

    Code sample: Connect and access SQL Server database in VB.NET 
    Imports System.Data.SqlClient  
     
    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            Dim con As SqlConnection = New SqlConnection("Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|\SqlDatabase.mdf")  
            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM AccessPage", con)  
            con.Open()  
            Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)  
            Dim myDataSet As DataSet = New DataSet()  
            myDA.Fill(myDataSet, "MyTable")  
            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView  
            con.Close()  
            con = Nothing 
        End Sub 
     
    End Class 


    The System.Data.OleDb namespace generally can be used to access MS Access database or Excel file.
    Code sample: Connect and access MS Access database in VB.NET
    Imports System.Data.OleDb  
     
    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=|DataDirectory|\myDB.mdb")  
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Table1", con)  
            con.Open()  
            Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)  
            Dim myDataSet As DataSet = New DataSet()  
            myDA.Fill(myDataSet, "MyTable")  
            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView  
            con.Close()  
            con = Nothing 
    End Sub 
     
    End Class 


    Trackback: http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/5980181e-f666-4f0a-ab50-c4ebecf96f02/


    Best regards,
    Martin Xie
    Thursday, March 19, 2009 4:35 AM
  • thank u Martin once again for u r reply 

    I am using SQLDMO in my project which provides the function of auto backup and restore

    but for using it ODbC driver is must 

    so i am asking for ODbC driver

    its not anything about creating a sqlconnection

    refer this link to know about SQLDMO


    plz reply for ODBC driver

    thanks
    Thursday, March 19, 2009 9:54 AM