Hi VB experts,
I just start to learn VB recently. I want to use VB to make figures. In each figures there are 7 to 8 lines to be plotted where the data points read from a data file. Firstly, I used the VB6 to write a code which can draw one figure on the screen. But I don't know how to make many figures and save into graphic file. The code is as follows:
________________________________________________
Dim numPhenotype As Integer, numChromosome As Single
Dim maxYvalue As Integer, maxSize As Integer
'maxYvalue = 6000
'maxSize = 50
Private Sub cmdDraw_Click()
Dim figure1 As New StdPicture
'Dim numPhenotype As Integer, numChromosome As Single
'Dim maxSize As Integer, i As Integer, maxYvalue As Integer
Dim i As Integer, j As Integer, k As Integer
Dim cc As String
Dim maxP As Single, maxI As Single, numMarker As Integer
numMarker = 8
numPhenotype = 1
numChromosome = 1
maxYvalue = 100
maxSize = 8
maxP = 1
maxI = 1
'ReDim numMarker(1 To maxSize) As Integer
ReDim Marker(1 To maxSize) As String
ReDim Phenotype(1 To maxSize) As String
ReDim iPressure(1 To maxSize) As Single
ReDim dPressure(1 To maxSize) As Single
ReDim sPressure(1 To maxSize) As Single
ReDim aPressure(1 To maxSize) As Single
ReDim iIndividual(1 To maxSize) As Single
ReDim dIndividual(1 To maxSize) As Single
ReDim sIndividual(1 To maxSize) As Single
ReDim aIndividual(1 To maxSize) As Single
'read numPhenotype and numChromosome
Open App.Path & "\FIGURE.TXT" For Input As #1
'Input #1, numPhenotype, numChromosome
'For i = 1 To numChromosome
'Input #1, numMarker(i)
'Next i
'For each chromosome
'For k = 1 To numChromosome
'For each QTL
'For i = 1 To numPhenotype
'For the markers
For j = 1 To numMarker
Input #1, Phenotype(j), cc, Marker(j), iPressure(j), iIndividual(j), _
dPressure(j), dIndividual(j), sPressure(j), sIndividual(j), _
aPressure(j), aIndividual(j)
'Find the maximiun value of 1/P and number of individual involved
If (iPressure(j) > maxP) Then
maxP = iPressure(j)
End If
If (dPressure(j) > maxP) Then
maxP = dPressure(j)
End If
If (sPressure(j) > maxP) Then
maxP = sPressure(j)
End If
If (aPressure(j) > maxP) Then
maxP = aPressure(j)
End If
If (iIndividual(j) > maxI) Then
maxI = iIndividual(j)
End If
If (dIndividual(j) > maxI) Then
maxI = dIndividual(j)
End If
If (sIndividual(j) > maxI) Then
maxI = sIndividual(j)
End If
If (aIndividual(j) > maxI) Then
maxI = aIndividual(j)
End If
Next j
'Scale number of individual into the same scale of inverse of pressure
'picOutput.Cls
'picBox.Print maxP
'picBox.Print maxP; maxI
For j = 1 To numMarker
iPressure(j) = iPressure(j) * maxYvalue / maxP
dPressure(j) = dPressure(j) * maxYvalue / maxP
sPressure(j) = sPressure(j) * maxYvalue / maxP
aPressure(j) = aPressure(j) * maxYvalue / maxP
iIndividual(j) = iIndividual(j) * maxYvalue / maxI
dIndividual(j) = dIndividual(j) * maxYvalue / maxI
sIndividual(j) = sIndividual(j) * maxYvalue / maxI
aIndividual(j) = aIndividual(j) * maxYvalue / maxI
Next j
'Call ReadData(label(), male(), female(), total())
'Call DrawAxes(maxYvalue, numMarker)
Call DrawAxes(numMarker)
Call DrawData(iPressure(), dPressure(), sPressure(), aPressure(), _
iIndividual(), dIndividual(), sIndividual(), aIndividual(), _
numMarker)
Call ShowTitle(numMarker)
Call ShowLabels(Marker(), numMarker, maxP, maxI)
Call ShowLegend
'Next i
'Next k
Close #1
End Sub
Private Sub DrawAxes(nMak As Integer)
'Draw axes
picLqtl.Scale (-1, 1.2 * maxYvalue)-(nMak + 1, -0.2 * maxYvalue)
picLqtl.Line (0, 0)-(nMak + 0.2, 0)
picLqtl.Line (0, 0)-(0, 1.1 * maxYvalue)
picLqtl.Line (nMak + 0.2, 0)-(nMak + 0.2, 1.1 * maxYvalue)
picLqtl.Line (0, 1.1 * maxYvalue)-(nMak + 0.2, 1.1 * maxYvalue)
End Sub
Private Sub DrawData(iPressure() As Single, dPressure() As Single, _
sPressure() As Single, aPressure() As Single, _
iIndividual() As Single, dIndividual() As Single, _
sIndividual() As Single, aIndividual() As Single, _
nMak As Integer)
Dim i As Integer
For i = 1 To nMak
If i < nMak Then
'Draw lines connecting data points
picLqtl.DrawStyle = 0
picLqtl.Line (i, iPressure(i))-(i + 1, iPressure(i + 1)), vbRed
picLqtl.DrawStyle = 1
picLqtl.Line (i, dPressure(i))-(i + 1, dPressure(i + 1)), vbBlue
picLqtl.DrawStyle = 2
picLqtl.Line (i, sPressure(i))-(i + 1, sPressure(i + 1)), vbGreen
picLqtl.DrawStyle = 3
picLqtl.Line (i, aPressure(i))-(i + 1, aPressure(i + 1)), vbYellow
picLqtl.DrawStyle = 4
picLqtl.Line (i, iIndividual(i))-(i + 1, iIndividual(i + 1)), vbBlack
picLqtl.DrawStyle = 5
picLqtl.Line (i, dIndividual(i))-(i + 1, dIndividual(i + 1)), vbWhite
picLqtl.DrawStyle = 4
picLqtl.Line (i, sIndividual(i))-(i + 1, sIndividual(i + 1)), vbCyan
picLqtl.DrawStyle = 0
picLqtl.Line (i, aIndividual(i))-(i + 1, aIndividual(i + 1)), vbMagenta
End If
'Draw small circles around data points
picLqtl.Circle (i, iPressure(i)), 0.01 * nMak
picLqtl.Circle (i, dPressure(i)), 0.01 * nMak
picLqtl.Circle (i, sPressure(i)), 0.01 * nMak
picLqtl.Circle (i, aPressure(i)), 0.01 * nMak
picLqtl.Circle (i, iIndividual(i)), 0.015 * nMak
picLqtl.Circle (i, dIndividual(i)), 0.015 * nMak
picLqtl.Circle (i, sIndividual(i)), 0.015 * nMak
picLqtl.Circle (i, aIndividual(i)), 0.015 * nMak
Next i
End Sub
Private Sub Locate(x As Single, y As Single)
picLqtl.CurrentX = x
picLqtl.CurrentY = y
End Sub
Private Sub ShowLabels(label() As String, nMak As Integer, maxP As Single, _
maxI As Single)
Dim i As Integer, lb1 As String, lblWid As Single
Dim lblHght As Single, tickFactor As Single
Dim lb2 As String, lb3 As String, lb4 As String
Dim lc1 As String, lc2 As String, lc3 As String, lc4 As String
'Draw tick marks and label them on x_axis
For i = 1 To nMak
lblWid = picLqtl.TextWidth(label(i))
tickFactor = 0.02 * maxYvalue
picLqtl.Line (i, -tickFactor)-(i, tickFactor)
Call Locate(i - lblWid / 2, -tickFactor)
picLqtl.Print label(i)
Next i
'Draw tick marks and label them on y_axis
'lbl = Str(maxYvalue)
'for inverse of significant
lb1 = Str(Int(maxP))
lb2 = Str(Int(0.75 * maxP))
lb3 = Str(Int(0.5 * maxP))
lb4 = Str(Int(0.25 * maxP))
tickFactor = 0.02 * nMak
lblWid = picLqtl.TextWidth(lb1)
lblHght = picLqtl.TextHeight(lb1)
picLqtl.Line (-tickFactor, maxYvalue)-(tickFactor, maxYvalue)
Call Locate(-tickFactor - lblWid, maxYvalue - lblHght / 2)
picLqtl.Print lb1
lblWid = picLqtl.TextWidth(lb2)
lblHght = picLqtl.TextHeight(lb2)
picLqtl.Line (-tickFactor, 0.75 * maxYvalue)-(tickFactor, 0.75 * maxYvalue)
Call Locate(-tickFactor - lblWid, 0.75 * maxYvalue - lblHght / 2)
picLqtl.Print lb2
lblWid = picLqtl.TextWidth(lb3)
lblHght = picLqtl.TextHeight(lb3)
picLqtl.Line (-tickFactor, 0.5 * maxYvalue)-(tickFactor, 0.5 * maxYvalue)
Call Locate(-tickFactor - lblWid, 0.5 * maxYvalue - lblHght / 2)
picLqtl.Print lb3
lblWid = picLqtl.TextWidth(lb4)
lblHght = picLqtl.TextHeight(lb4)
picLqtl.Line (-tickFactor, 0.25 * maxYvalue)-(tickFactor, 0.25 * maxYvalue)
Call Locate(-tickFactor - lblWid, 0.25 * maxYvalue - lblHght / 2)
picLqtl.Print lb4
'For number of individual
lc1 = Str(Int(maxI))
lc2 = Str(Int(0.75 * maxI))
lc3 = Str(Int(0.5 * maxI))
lc4 = Str(Int(0.25 * maxI))
tickFactor = 0.02 * nMak
lblWid = picLqtl.TextWidth(lc1)
lblHght = picLqtl.TextHeight(lc1)
picLqtl.Line (nMak + 0.1, maxYvalue)-(nMak + 0.1 + tickFactor, maxYvalue)
Call Locate(nMak + 0.9 - lblWid, maxYvalue - lblHght / 2)
picLqtl.Print lc1
lblWid = picLqtl.TextWidth(lc2)
lblHght = picLqtl.TextHeight(lc2)
picLqtl.Line (nMak + 0.1, 0.75 * maxYvalue)-(nMak + 0.1 + tickFactor, 0.75 * maxYvalue)
Call Locate(nMak + 0.9 - lblWid, 0.75 * maxYvalue - lblHght / 2)
picLqtl.Print lc2
lblWid = picLqtl.TextWidth(lc3)
lblHght = picLqtl.TextHeight(lc3)
picLqtl.Line (nMak + 0.1, 0.5 * maxYvalue)-(nMak + 0.1 + tickFactor, 0.5 * maxYvalue)
Call Locate(nMak + 0.9 - lblWid, 0.5 * maxYvalue - lblHght / 2)
picLqtl.Print lc3
lblWid = picLqtl.TextWidth(lc4)
lblHght = picLqtl.TextHeight(lc4)
picLqtl.Line (nMak + 0.1, 0.25 * maxYvalue)-(nMak + 0.1 + tickFactor, 0.25 * maxYvalue)
Call Locate(nMak + 0.9 - lblWid, 0.25 * maxYvalue - lblHght / 2)
picLqtl.Print lc4
End Sub
'Private Sub ShowLegend(maxE As Integer)
Private Sub ShowLegend()
'Show legend
'picLqtl.DrawStyle = 1
'picLqtl.Line (0.1, 1.05 * maxYvalue)-(0.9, 1.05 * maxYvalue)
'Call Locate(1, 1.1 * maxYvalue)
'picLqtl.Print "1/Sig."
'picLqtl.DrawStyle = 4
'picLqtl.Line (0.1, 0.95 * maxYvalue)-(0.9, 0.95 * maxYvalue)
'Call Locate(1, 1.01 * maxYvalue)
'picLqtl.Print "# of Ind."
'picLqtl.DrawStyle = 0
'picLqtl.Line (0.1, 0.85 * maxYvalue)-(0.9, 0.85 * maxYvalue)
'Call Locate(1, 0.9 * maxYvalue)
'picLqtl.Print "Total"
End Sub
Private Sub ShowTitle(nMak As Integer)
'Display source and title
Call Locate(2, -0.1 * maxYvalue)
picLqtl.Print " The Genotype"
Call Locate(-0.5, 1.2 * maxYvalue)
picLqtl.Print "Signaficance"
Call Locate(nMak - 0.8, 1.2 * maxYvalue)
picLqtl.Print "# of Individual"
End Sub
One chunck of my data file(FIGURE.TXT) like this:
"birth_W", "chr_001", "Sw373", 0.201E+01, 110, 0.137E+01, 129, 0.194E+01, 129, 0.132E+01, 220
"birth_W", "chr_001", "Sw780", 0.175E+01, 91, 0.109E+01, 128, 0.355E+01, 128, 0.175E+01, 219
"birth_W", "chr_001", "Sw64 ", 0.359E+01, 47, 0.125E+01, 50, 0.213E+01, 50, 0.120E+01, 109
"birth_W", "chr_001", "S0008", 0.331E+01, 104, 0.148E+01, 195, 0.134E+01, 195, 0.170E+01, 234
"birth_W", "chr_001", "Sw1301", 0.622E+01, 117, 0.185E+01 207, 0.191E+01, 207, 0.104E+01, 258
"birth_W", "chr_001", "Sw1430", 0.190E+01, 227, 0.140E+01, 237, 0.322E+01, 237, 0.117E+01, 246
"birth_W", "chr_001", "Sw1824", 0.453E+02, 173, 0.505E+01, 226, 0.215E+01, 226, 0.146E+01, 231
"birth_W", "chr_001", "S0155", 0.119E+01, 161, 0.231E+01, 235, 0.215E+01, 235, 0.111E+01, 235
_____________________________________________________
Now I want to switch to VB2005 and try to make the figures like:
Since each time I have to make hundreds figures, I want to display the figure on the screen and save them into graphic file. Each page and screen) can display 1, 2,4 or 6 figures.
Since I'm new for VB2005, I don't know how to make a control to handle this. Such as display figure on screen one by one or two by two etc and save them into graphic file(s).
Is there someone who can give me some suggestions or a template programming scheme to feed my needs Especially, (1) from control form how to get into graphic mode(such as pictureBox, etc) where I can draw my figures; (2) The controls to plot the figure one by one; (3) how to save into graphic files.
Thank you very much for your kind help.
Yuhua

How to make several figures and save in graphic files?
fiza
Thank you very much for your suggestions.
There are still some issues I could not know how to handle. Below is my unfinished VB2005 code.
(1) The first issue is that when I click button3(see sub button3_click) I want to get into either a pictureBox or a new form where I can start to draw figures. But I couldn't get there by calling sub draw_figure1(or 2 or 3 or 4 depends on how many figures to be shown on screen each time). It seems these sub should be a handler, but I don't know how to set it. I plan to convert my VB6 code and put them into these subroutines to get the figure. I think I still have some problem during this converting process, such as how to read data file, how to use graphic class which is different from VB6, etc.
(2) How to set a control(a counter ) to make many figures which can be shown on screen and saved into graphic file.
Can you provide me a template scheme to handle my case Thank you very much for your help. yd
---------------------------------------
Option Explicit On Option Strict On Imports System Imports System.IO Imports Microsoft.VisualBasic Public Class Form1 Dim num_chr As Integer Dim num_trait As Integer Dim num_marker As Integer Dim num_fig_perpage As Integer Dim num_page As Integer Dim num_fig As Integer Dim maxYvalue As Integer = 100 Dim maxSize As Integer Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub TableLayoutPanel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged 'Dim num_fig_per_page As Integer num_fig_perpage = CInt(ListBox1.Text) End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Total_fig As Integer Dim Total_fig_msg As String Total_fig = num_chr * num_trait Total_fig_msg = "Total number of figures = " & Total_fig.ToString() MessageBox.Show(Total_fig_msg) End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged 'Dim num_marker As Integer num_marker = Integer.Parse(TextBox1.Text) End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged 'Dim num_trait As Integer num_trait = Integer.Parse(TextBox2.Text) End Sub Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click End Sub Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged num_chr = CInt(TextBox3.Text) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If (num_fig_perpage = 1) Then Call Draw_figure_1() 'Call Form1_load() ElseIf (num_fig_perpage = 2) Then Call Draw_figure_2() ElseIf (num_fig_perpage = 4) Then Call Draw_figure_3() ElseIf (num_fig_perpage = 6) Then Call Draw_figure_4() Else MessageBox.Show("The number of figure per page must be 1,2,4, or 6") End If End Sub 'Private Sub Form1_load(ByVal sender As System.Object, _ 'ByVal e As System.EventArgs) Handles MyBase.Load 'Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red) 'Dim formGraphics As System.Drawing.Graphics 'formGraphics = Me.CreateGraphics() 'formGraphics.DrawLine(myPen, 0, 0, 200, 200) 'myPen.Dispose() 'formGraphics.Dispose() 'End Sub Private Sub Draw_figure_1() Dim i As Integer, j As Integer, k As Integer Dim cc As String Dim maxP As Single, maxI As Single, numMarker As Integer numMarker = 8 num_chr = 1 num_trait = 1 maxYvalue = 100 maxSize = 50 maxP = 1 maxI = 1 Dim Marker(0 To maxSize) As String Dim Phenotype(0 To maxSize) As String Dim iPvalue(0 To maxSize) As Single Dim dPvalue(0 To maxSize) As Single Dim sPvalue(0 To maxSize) As Single Dim aPvalue(0 To maxSize) As Single Dim iIndiv(0 To maxSize) As Single Dim dIndiv(0 To maxSize) As Single Dim sIndiv(0 To maxSize) As Single Dim aIndiv(0 To maxSize) As Single Const FILE_NAME As String = "Figure.TXT" If Not File.Exists(FILE_NAME) Then Console.WriteLine("{0} does not exist.", FILE_NAME) Return End If FileOpen(1, FILE_NAME, OpenMode.Input) 'Dim rrr As StreamReader = File.OpenText(FILE_NAME) 'For i = 1 To numMarker 'Input(1, Phenotype(j), cc, Marker(j), iPvalue(j), iIndiv(j), _ 'dPvalue(j), dIndiv(j), sPvalue(j), sIndiv(j), aPvalue(j), aIndiv(j)) 'Next 'Dim Figure_1 As New PictureBox 'Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red) 'Dim formGraphics As System.Drawing.Graphics 'formGraphics = Me.CreateGraphics() 'formGraphics.Clear(Color.Cyan) 'formGraphics.DrawLine(myPen, 0, 0, 200, 200) 'myPen.Dispose() 'formGraphics.Dispose() End Sub Private Sub Draw_figure_2() End Sub Private Sub Draw_figure_3() End Sub Private Sub Draw_figure_4() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click MessageBox.Show("You don't want to calculate the total number of figure") End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.Close() End Sub End Class --------------------------------------------------------Karen Gayda
You will want to make the drawing of the figures take place inside of a routine that takes a Graphics instance as a parameter. This is so that if you want to save a picture to a bitmap file, you can pass it the graphic made from Bitmap.CreateGraphics but when you are only drawing to the screen, you can pass in the graphics from the PaintEventArgs.
Also, you may look into the System.IO namespace which is the ".NET way" of reading and writing text files.
Some other observations about the code you posted:
If (iPressure(j) > maxP) Then
maxP = iPressure(j)
End If
If (dPressure(j) > maxP) Then
maxP = dPressure(j)
End If
If (sPressure(j) > maxP) Then
maxP = sPressure(j)
End If
If (aPressure(j) > maxP) Then
maxP = aPressure(j)
End If
could be rewritten as
Select Case maxP
Case < aPressure(j)
maxP = aPressure(j)
Case < sPressure(j)
maxP = sPressure(j)
Case < dPressure(j)
maxP = dPressure(j)
Case < iPressure(j)
maxP = iPressure(j)
End Select
and this
For j = 1 To numMarker
iPressure(j) = iPressure(j) * maxYvalue / maxP
dPressure(j) = dPressure(j) * maxYvalue / maxP
sPressure(j) = sPressure(j) * maxYvalue / maxP
aPressure(j) = aPressure(j) * maxYvalue / maxP
iIndividual(j) = iIndividual(j) * maxYvalue / maxI
dIndividual(j) = dIndividual(j) * maxYvalue / maxI
sIndividual(j) = sIndividual(j) * maxYvalue / maxI
aIndividual(j) = aIndividual(j) * maxYvalue / maxI
Next j
and this could be rewritten as
pyScale = maxYvalue / maxP
iyScale = maxYvalue / maxI
For j = 1 To numMarker
iPressure(j) *= pyScale
dPressure(j) *= pyScale
sPressure(j) *= pyScale
aPressure(j) *= pyScale
iIndividual(j) *= iyScale
dIndividual(j) *= iyScale
sIndividual(j) *= iyScale
aIndividual(j) *= iyScale
Next
net34
Imports System.IO
Public Class ChromosomePicture
Inherits Control
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics = e.Graphics
'drawing routine here
End Sub
Private Const maxSize As Integer = 50
Private iChrom As New Chromosome(maxSize)
Private dChrom As New Chromosome(maxSize)
Private sChrom As New Chromosome(maxSize)
Private aChrom As New Chromosome(maxSize)
Private phenotype(maxSize) As Single
Private marker(maxSize) As Single
Public Sub LoadFile(ByVal fileName As String)
If Not File.Exists(fileName) Then Throw New FileNotFoundException(fileName & " does not exist.")
Dim maxP As Single = 1
Dim maxI As Single = 1
Dim numMarker As Integer = 8
Dim line As String
Dim parts() As String
Using sr As New StreamReader(fileName)
For i As Integer = 0 To numMarker
line = sr.ReadLine
parts = line.Split(","c)
phenotype(i) = Single.Parse(parts(0))
marker(i) = Single.Parse(parts(2))
iChrom.SetValues(parts, 3, i)
dChrom.SetValues(parts, 5, i)
sChrom.SetValues(parts, 7, i)
aChrom.SetValues(parts, 9, i)
Next
End Using
'forces redraw
Me.Invalidate()
End Sub
End Class
and here's a little helper class for all those arrays
Public Class Chromosome
Private Const default_size As Integer = 0
Public Sub New()
Me.New(default_size)
End Sub
Public Sub New(ByVal maxSize As Integer)
_pvalue = CType(Array.CreateInstance(GetType(Single), maxSize), Single())
_indiv = CType(Array.CreateInstance(GetType(Single), maxSize), Single())
End Sub
Private _pvalue As Single()
Public Property PValue() As Single()
Get
Return _pvalue
End Get
Set(ByVal value As Single())
If value Is Nothing Then Throw New NullReferenceException("value")
_pvalue = value
End Set
End Property
Private _indiv As Single()
Public Property Individual() As Single()
Get
Return _indiv
End Get
Set(ByVal value As Single())
If value Is Nothing Then Throw New NullReferenceException("value")
_indiv = value
End Set
End Property
Public Sub SetValues(ByVal values() As String, ByVal start As Integer, ByVal index As Integer)
Me.PValue(index) = Single.Parse(values(start))
Me.Individual(index) = Single.Parse(values(start + 1))
End Sub
Public Sub SetValues(ByVal values() As Single, ByVal start As Integer, ByVal index As Integer)
Me.PValue(index) = values(start)
Me.Individual(index) = values(start + 1)
End Sub
End Class
and here are some routines from the form that could use changing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Total_fig As Integer = num_chr * num_trait
MessageBox.Show("Total number of figures = " & Total_fig.ToString())
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Select Case num_fig_perpage
Case 1
Draw_figure_1()
Case 2
Draw_figure_2()
Case 4
Call Draw_figure_3()
Case 6
Call Draw_figure_4()
Case Else
MessageBox.Show("The number of figure per page must be 1,2,4, or 6")
End Select
End Sub
The draw_figure routines will not be needed any more since the painting will be done in the custom control. The reason that painting directly on the form does not work is because you would have to paint each time the form paints. To change pictures, you will want to make a new ChromosomeControl (or whatever you want to call it) and place it inside a panel on the form.
curChrom = new ChromosomeControl()
'initialize control
panel1.Controls.Clear()
panel1.Controls.Add(curChrom)
Obviously this is nowhere near completed, but hopefully it is enough to get you going in the right direction.