Posts

Showing posts from October, 2012

Class And Structure.

Dear Developers              I would like to share something which i found while performing one of the development task. Working difference between Class Objects and Structure Objects. If you see them they both are same in low level of the working. Classes has much more feature compared to Structures. The choose come when you have limit property and basis feature needed. Lets see the working Public Class Person     Dim strName As String     Public Property Name() As String         Get             Return strName         End Get         Set(ByVal value As String)             strName = value         End Set   ...

UNION ALL And Order BY

Dear Friends                       I have come across feature in SQL server which is less known to developers. Union ALL and Order by together. Fill combo box with union of two tables and order by Ascending. I would normally write it as   SQL :- Select  PersonName From (     Select PersonName From TranPersonDetails     Union All     Select CompanyName From TranCompanyDetails ) AllData Order by PersonName   Look into above SQL :- Additonal Select statment on top to add order by. Found easier way to provide order without Top Select Statement   SQL :- Select PersonName From TranPersonDetails Union All Select CompanyName From TranCompanyDetails Order By PersonName   No need to have additonal Select Statment. Order by will work for bo...

Count Line in Multiline Label Control

My New Task Count Total Number Lines in Label Control. Function LineCount(ByVal Label As Label) As Integer   Dim g As Graphics = Label.CreateGraphics     Dim LineHeight As Single = g.MeasureString("X", Label.Font).Height))   Dim TotalHeight As Single = g.MeasureString(Label.Text, Label.Font, Label.Width).Height     Return CInt(Math.Round(TotalHeight / LineHeight)) End Function

Get String value from a Enum

My New Task Get String value from a Enum     Enum TestingEnum As Integer         A = 0         B = 1         C = 2         D = 3     End Enum     Dim Value As TestingEnum     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Value = TestingEnum.B     End Sub     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click    MsgBox(Value.ToString)  'Simplest of ways         Dim val As Object         val = [Enum].GetName(GetType(TestingEnum), Value)         Msgbox(val) ' Will Return B     End Sub

Store Image From Picture Box To SQL SERVER

My New Task Save Image from Picturebox to Sql Server Table. Dim stream As New MemoryStream() picEmp.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg) Dim oImgByteArray() As Byte oImgByteArray()  = stream.ToArray Dim SQLCmd As New SqlCommand SQLCmd.Connection = cnSQL SQLCmd.Parameters.Add(New SqlParameter("@Img", SqlDbType.Image)).Value = oImgByteArray SQLCmd.CommandText = "Insert Into CMS.mastImageStoreage (Img) Values (@Img)" SQLCmd.ExecuteNonQuery() stream.close SQLCmd.Dispose Note : This is why love working on .net platform. If you were suppose perform same in VB 6.0. Physical file is need in path and than only you can save. Think  bring same from database. You have create physical file in drive and load it from there. 

Load Form With Out Focus In Windows Forms

My New Task  For some reason you want form to be shown without focus on it. you can have ShowWithoutActivation() Property. there is trick to use this property Currently this tied with form Object [Me.ShowWithoutActivation] but you cannot use this. As this Readonly property. So to perform this Following Steps has to be performed 1.Open the form Designer file. [Form1.Designer.vb] 2.Place this code in last line of the file What it does. This overrides the built in method for form     Protected Overrides ReadOnly Property ShowWithoutActivation() As Boolean         Get             Return True         End Get     End Property Note :- I have used this to shown popup message in systray 

Write Text in image

My New Task, Feature which allow user to select images with single click with sequence number shown on image as part of selection. Public Sub ImageProcessing(ByVal Counter As Integer, ByVal RowIndex As Integer, ByVal ColIndex As Integer, Optional ByVal ArrayImage() As Byte = Nothing)         Dim byteArrayIn() As Byte         Dim ms As MemoryStream         Dim sourceImage As Image         If IsNothing(ArrayImage) = True Then             byteArrayIn = grdStudent.Item(RowIndex, ColIndex).CellValue         Else             byteArrayIn = ArrayImage         End If         ms = New MemoryStream(byteArrayIn)         sourceImage = Image.FromStream(ms)         'Resize Image so that text Can have shown proper, as images are of different si...