SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
SETHA SITE INFORMATION

Using window, textbackground, textcolor, gotoxy in Turbo C++

E-mail Print PDF

The below code is written in Turbo C++. It includes the uses of window, textbackground, textcolor, and gotoxy functions. There are 8 main colors in this context. (0:BLACK, 1:BLUE, 2:GREEN, 3:CYAN, 4:RED, 5:MAGENTA, 6:BROWN, 7:LIGHTGRAY)

1) Two Windows Example
#include<stdio.h>
#include<conio.h>

void main()
{
	//full screen window w: 80, h: 50
	window(1,1,80,50);
	textbackground(0);//black color
	clrscr();
	textcolor(15); //white color
	gotoxy(1,1); cprintf("WINDOW-1");

	//window 2
	window(10,10,40,20);
	textbackground(1); //blue color
	clrscr();
	textcolor(15); //white color
	gotoxy(1,1); cprintf("WINDOW-2");
	//pause screen
	getch();
}
Download Source Code Here
 
2) 8 Windows Example
#include<stdio.h>
#include<conio.h>

void main()
{
	for(int i=0; i<=7; i++)
	{
		window(1+5*i,1+3*i,80-5*i,50-3*i);
		textbackground(7-i);//black color
		clrscr();
		textcolor(i); //white color
		gotoxy(2,2); cprintf("WINDOW-%d",8-i);
	}

	//pause screen
	getch();
}
Download Source Code Here
 
3) 16 Windows Example
#include<stdio.h>
#include<conio.h>

void main()
{
	for(int i=0; i<=15; i++)
	{
		window(1+5*i,1,5+5*i,50);
		textbackground(7-i);//black color
		clrscr();
		textcolor(i); //white color
		gotoxy(2,2); cprintf("%d",i+1);
	}

	//pause screen
	getch();
}
Download Source Code Here
 

Calculate Factoriel in Turbo C++

E-mail Print PDF
Code below is the C++ programming language uses to calculate factorial of value n using recursive function (return n*fact(n-1).
n! = 1 x 2 x 3 x 4 x ... x n
long fact(int n)
{
	if(n==0) return 1;
	else return n*fact(n-1);
}
 

How to Draw Line in Visual Basic .Net Using Mouse Pointer?

E-mail Print PDF

This article shows you how to create a small Visual Basic .Net project using Mouse Pointer to draw line in a PictureBox control. Mouse Pointer events (MouseDown, MouseMove, and MouseUp) are used in this article. However, if you draw a new line pass through some parts of the existing line in the box then it will erase those parts.

Note: picRegion in code below is a name of PictureBox control
  • Global Variable
    Private startX As Integer = 0   'start position x of line
    Private startY As Integer = 0   'start position y of line
    Private oldEndX As Integer = 0  'the previous ending position x
    Private oldEndY As Integer = 0  'the previous ending position y
    Private gBitmap As Bitmap       'bitmap to place in picturebox
    Private isMouseDown As Boolean = False  'recognize mouse down or up
    
  • Mouse Down Event: is to get position X and Y for the beginning point of line.
    Private Sub picRegion_MouseDown(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles picRegion.MouseDown
            isMouseDown = True
            startX = e.X
            startY = e.Y
    End Sub
    
  • Mouse Move Event: process only while mouse pointer being pressed.
    1. Delete previous line by draw another line with background color
    2. Draw another line with black color with the current ending point
    Private Sub picRegion_MouseMove(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.MouseEventArgs) _
            Handles picRegion.MouseMove
            If isMouseDown = True Then
                'draw line during move
                Dim g As Graphics = Graphics.FromImage(gBitmap)
                g.DrawLine(New Pen(Me.picRegion.BackColor), startX, startY, oldEndX, oldEndY)
                picRegion.Image = gBitmap
    
                g.DrawLine(Pens.Black, startX, startY, e.X, e.Y)
                picRegion.Image = gBitmap
                '
                oldEndX = e.X
                oldEndY = e.Y
            End If
    End Sub
    
  • Mouse Up Event: just note that mouse pointer does not pressed anymore.
    Private Sub picRegion_MouseUp(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles picRegion.MouseUp
            isMouseDown = False
    End Sub
    
  • Form Load: create new bitmap object to be a region for drawing
    Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Load
            gBitmap = New Bitmap(picRegion.Width, picRegion.Height)
    End Sub
    

Download Source Code Here
 

Getting Start with DataGridView Control in Visual Basic 2008

E-mail Print PDF

This article enclosed with video clip shows you to get start using the DataGridView Control in Visual Basic .Net.

  • Add Columns to DataGridView
  • Define Column Width
  • Add Data to DataGridView

'add column
With Me.DataGridView1
   .Columns.Add("id", "ID")
   .Columns.Add("name", "Name")
   .Columns.Add("sex", "Sex")
End With

'define columns width
With Me.DataGridView1
   .Columns("id").Width = 200
   .Columns("name").Width = 500
   .Columns("sex").Width = 100
End With

'add data (10 rows)
For i As Integer = 1 To 10
    Me.DataGridView1.Rows.Add()
    With Me.DataGridView1.Rows(Me.DataGridView1.Rows.Count - 2)
        .Cells("id").Value = i
        .Cells("name").Value = "Name " & i
        .Cells("sex").Value = "M"
    End With
Next
 

How to Draw Shape (Line, Rectangle, Pie) in Visual Basic .Net?

E-mail Print PDF

This article uses Visual Basic .Net code to draw Line, Rectangle and Pie within a Form object.

Draw Two Lines
Dim g As Graphics = Me.CreateGraphics()
g.DrawLine(Pens.Black, 50, 70, 100, 250)
g.DrawLine(Pens.Black, 120, 70, 120, 250)
Draw a Rectangle (Width=100, Height=200)
Dim g As Graphics = Me.CreateGraphics
g.DrawRectangle(Pens.Blue, 220, 70, 100, 200)
Draw a Pie (Height=200, Width=100, Angle=270)
Dim g As Graphics = Me.CreateGraphics
g.DrawPie(Pens.Red, 400, 70, 100, 200, 0, 270)

Download Code Here
 


Page 4 of 19