-->

Friday, December 25, 2015

Solve Application not responding problem

In this article, I will show you how to fix computer hanging problems. Generally, we all know about "Not Responding" problem. When processor takes time to execute the process then thats type of problem occurs. By using this article, I will resolve this issue.




Windows Form Design:

Solve Application not responding problem
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        private readonly SynchronizationContext synchronizationContext;
        private DateTime previousTime = DateTime.Now;
        public Form1()
        {
            InitializeComponent();
            synchronizationContext = SynchronizationContext.Current;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (var i = 0; i <= 1000000; i++)
            {
                label1.Text = @"Count : " + i;
            }
        }

        private async void button2_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            var count = 0;

            await Task.Run(() =>
            {
                for (var i = 0; i <= 1000000; i++)
                {
                    UpdateUI(i);
                    count = i;
                }
            });
            label1.Text = @"Count : " + count;
            button1.Enabled = true;
            button1.Enabled = false;
        }
        public void UpdateUI(int value)
        {
            var timeNow = DateTime.Now;

            //Here we only refresh our UI each 50 ms
            if ((DateTime.Now - previousTime).Milliseconds <= 50) return;

            //Send the update to our UI thread
            synchronizationContext.Post(new SendOrPostCallback(o =>
            {
                label1.Text = @"Count : " + (int)o;
            }), value);

            previousTime = timeNow;
        }
    }
}

How to bind Bulleted List control in asp.net

Following some steps for binding bulleted list control using SqlDataSource

In this article, I will show you, How to bind BulletedList in ASP.NET. In this article, I will take SQL DataSource control to bind it. ASP.NET Provide inbuilt control to bind any other control like ListBox, ComboBox, BulletedList. After bind it, it will look like list of unordered list of HTML.Lets  to Start how to bind it. I will Give you, video as well as code for this.




Step-1 : Open visual studio
Step-2:  Click  File-->New-->WebSite
starting screen

Step-3: Right click on website name in solution explorer, Add-->Add new item 

web form


Step-4: Make Database table 
Step-5: Drag Bulleted list from toolbox and drop on design window.
Step-6: Select Show smart tag of Bulleted list
show smart tag

Step-7: On Bulledted list task click choose data source link
Step-8: Select New DataSource from Data Source configuration wizard.

choose data source

Step-9: Select SQL Database from Data Source Configuration wizard. and click ok button

data configuration wizard

Step-10 : Select existing database from configure data source.

connection string property

Step-11 : Change Connection name according to you and click ok
web.config file

Step-12 : Select table from name ,select table field name and press ok button

table view

Step-13: Click test query button and finish the process
Step-14: Select a data field to display in the bulleted list.
Step-15: Select a data field for the value of the bulleted list. and press ok button
select one those field in bulleted list

Run your application
how to bind bulleted list in asp.net

Finally source of the code are:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name " DataValueField="Url">
        </asp:BulletedList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [mytab]"></asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
Top Related Article

Tuesday, December 22, 2015

Example of Customized TabItem of TabControl in WPF

Customized Tab Item Example:
Tab Item is the item control of Tab control. In this article, I will show you, how to add images, TextBlock and any other control inside TabControl. Also I will show you how to move Tab Control's tabs using buttons like Pre, Next, Get Item of Selected tab. When we press Previous button then next tab move to previous button. Similarly for all buttons. 



<Window x:Class="WpfApplication9.tabcon"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="tabcon" Height="300" Width="300">
    <Grid>
        <!--<TabControl>
            <TabItem Header="First Item">
                <Label Content="Items in the first tab"/>
            </TabItem>
            <TabItem Header="Second Item"/>
            <TabItem Header="Third Item"/>
           
           
        </TabControl>-->
        <DockPanel>
            <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
                <Button Name="prebutton" Click="prebutton_Click" Height="36" Width="54">Pre</Button>
                <Button Name="Nextbutton" Click="Nextbutton_Click"  Height="36" Width="54">Next</Button>
                <Button Name="selectbutton" Click="selectbutton_Click"  Height="36" Width="54">select</Button>
            </StackPanel>
            <TabControl Name="sample">
                <TabItem Header="First Item">
                    <Label Content="Content in First tab"/>
                </TabItem>
                <TabItem>
                    <TabItem.Header>
                        <TextBlock Text="Second Tab" Foreground="Red"/>
                    </TabItem.Header>
                </TabItem>
                <TabItem Header="Third Tab"/>
            </TabControl>
           
        </DockPanel>
    </Grid>
</Window>

Code Behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication9
{
    /// <summary>
    /// Interaction logic for tabcon.xaml
    /// </summary>
    public partial class tabcon : Window
    {
        public tabcon()
        {
            InitializeComponent();
        }

        private void prebutton_Click(object sender, RoutedEventArgs e)
        {
            int nindex = sample.SelectedIndex - 1;
            if (nindex < 0)
                nindex = sample.Items.Count - 1;
            sample.SelectedIndex = nindex;
        }

        private void Nextbutton_Click(object sender, RoutedEventArgs e)
        {
            int nindex = sample.SelectedIndex + 1;
            if (nindex >= sample.Items.Count)
                nindex = 0;
            sample.SelectedIndex = nindex;
        }

        private void selectbutton_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Selected Tab is:" + (sample.SelectedItem as TabItem).Header);
        }
    }
}

Wednesday, December 16, 2015

Example of Context menu in WPF

Context Menu Introduction:
Context menu means a window appear when we click on right button of mouse on selected Text. Today, we will design context menu with the help of WPF. Here, we will take a Input control with context menu also context menu contain MenuItem.



XAML Code
<Grid>
        <RichTextBox >
            <RichTextBox.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="Cut">
                        <MenuItem.Icon>
                            <Image Source="apple.png"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="Copy">
                        <MenuItem.Icon>
                            <Image Source="grapes.png"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>              
               
            </RichTextBox.ContextMenu>
                 
           
        </RichTextBox>

    </Grid>
Suppose, your richTextBox is disabled and you want to show context menu on disabled item then use this code:

<RichTextBox IsEnabled="False" ContextMenuService.ShowOnDisabled="True">

Saturday, December 12, 2015

AWT Frame close using close Button

In AWT Java we have a Frame class which is inherit from window class. If you are a beginner in AWT Java then you know that Frame doesn't close when we press close button of it. So, In last we pressed stop debugging button in Netbeans IDE. If you want to close Frame using Close button, which is see in top right corner of Frame then you should implement code for it. 


Complete Java Code


package awtframe;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class AWTFrame {

    public AWTFrame()
    {
        Frame f1=new Frame("Welcome to Closing");
        f1.setSize(500,500);
        f1.setVisible(true);
       
        f1.addWindowListener(new WindowAdapter(){
           
            @Override
            public void windowClosing(WindowEvent e)
            {
              System.exit(0);
            }
           
        });
       
       
    }
    public static void main(String[] args) {
     
       AWTFrame at=new AWTFrame();
       
    }
   
}

Here, we have windowClosing ( ) method to close Frame using close button.

Thursday, December 10, 2015

How to pass data from controller to view in ASP.NET MVC

If you want to pass value from controller to view in asp.net MVC, we have two methods. The first method of it is ViewBag and last is ViewData, both are used to pass data from controller to view. ViewBag object creates a dynamic variable and ViewData creates a dynamic key like ViewState in ASP.NET.  Learn, How to use ViewBag in MVC for single variable as well as List<String> type variable. 


In controller class, we used ViewBag.Dynamic_variable = "Value" and in View we used @ViewBag.Dynamic_Variable_Name. Also, learn how to pass value from controller to view using ViewData.



Both objects doesnot generate compile time error.

Tuesday, December 8, 2015

Password Box example in WPF

If you want to design login control then must to set the special character in password box. Today, we will learn, how to design password box in WPF. In WPF, we have a PasswordBox tag in XAML , through this we can add Password box in WPF. I have a simple login control through you can see password control.



The complete code of login control

<Window x:Class="WpfApplication8.password"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="password" Height="300" Width="300">
    <Grid> 
        <StackPanel Margin="20">
            <Label>Password Box Example</Label>
            <WrapPanel>
                <Label>Username:</Label>
                <TextBox Width="100"/>
            </WrapPanel>
            <WrapPanel>
                <Label>Password:</Label>
                <PasswordBox PasswordChar="x" MaxLength="8" Width="100"/>
            </WrapPanel>
            
            
        </StackPanel>
        
    </Grid>
</Window>

Code Generates the following output:


© Copyright 2013 Computer Programming | All Right Reserved