For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Thursday, May 22, 2014

Child form open and close problem in MDIForm C#

Child form open and close problem in MDIForm C#

===================================================================================
You have a menu item in MDIForm, after clicking on that a child form will be shown.
If you close the child form by clicking in cross "X" button which is on
right top corner, the child form will be closed.
And if you again click on MDIForm's menu item then the child form will not show.
This is because child form is disposed but that's variable is not null.
Listed below the code is the good example of that problem:
-----------------------------------------------------------------------------------
namespace MyProject
{
    public partial class AdminMDIParent : Form
    {
        Synopsis synopsis=null;
    }

    private void ShowNewForm(object sender, EventArgs e)
        {
            if (synopsis == null)
                {
                    synopsis = new Synopsis();
                    synopsis.MdiParent = this;

        }
              synopsis.Show();
              synopsis.Focus();
        }

}
-----------------------------------------------------------------------------------
The above code will not show the form in second time and rest. This is because the "synopsis"
is the object of "Synopsis" Form class. and this is the local variable of AdminMDIParent" class.
Only first time that code will work. So how to overcome this problem?
by the way, You will just use this code:
private void ShowNewForm(object sender, EventArgs e)
{
    synopsis = new Synopsis();
        synopsis.MdiParent = this;
    synopsis.Show();
        synopsis.Focus();
}
But the problem is when you use the above code and click again and again MDIForm's menu item without
closing child form; the multiple child form will be shown.
-----------------------------------------------------------------------------------

So to overcome this problem; we check its "visible" property as listed below.  Listed below code work fine.
private void ShowNewForm(object sender, EventArgs e)
{
    if (synopsis == null || synopsis.Visible==false)
    {
        synopsis = new Synopsis();
        synopsis.MdiParent = this;
    }
        synopsis.Show();
        synopsis.Focus();
}
-----------------------------------------------------------------------------------
Share:

bottom to top scroll in html

bottom to top scroll in html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
#back-to-top {
     position: fixed;
     bottom: 30px;
     top: 350px;
}
#back-to-top img{
    cursor:pointer;
}
</style>
<script language="javascript" src="jquery-1.10.2.js" type="text/javascript"></script>
</head>
<body>
<h1>Back To Top</h1>
<p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p>
<p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p>
<p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p>
<p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p>
<p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p><p>fsdfsdfsdf</p>
<div style="height:1000px"></div>
<span id="back-to-top"><img id="bus" src='bus.gif'/></span>
</body>
<script type="text/javascript">
        $(document).ready(function () {
            $("#back-to-top").hide();
            $(window).scroll(function () {
                if ($(window).scrollTop() > 200) {
                    $('#back-to-top').fadeIn();
                } else {
                    $('#back-to-top').fadeOut();
                }
            });
              $('#back-to-top img').click(function () {   
               var body = $("body, html");
               body.animate({scrollTop :0}, '1500',function(){ });
            });
        });
    </script>
</html>
Share:

Page not found error 404 message customize in php


Page not found error 404 message customize in php.


1) if you have the local server "http://localhost" and you site root folder is "/test/myht/" then your url will be as:
"http://localhost:90/test/myht/"
create a file "404.html" or any other name. and paste the message as :
<h1> My custome error message for file not found.. file not found </h1>


2)Create ".htaccess" file and make the listed below entry

RewriteEngine on
ErrorDocument 404 /test/myht/404.html

if WAMP or LAMP is alreay "ON" the restart it.
open browser and try to url as:
http://localhost/test/myht/1.html

you will found your customization message as:

"My custome error message for file not found.. file not found".
Share:

Wednesday, May 07, 2014

Mouse Pointer info in java

Mouse Pointer info in java


Suppose you move your mouse pointer in entire desktop area and want to know the exact position of the mouse. then use listed below code. by this code you can get the real mouse position X and Y .



import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
class ShowMyMouse extends Thread {
    public ShowMyMouse(String str) {
        super(str);
    }
    public void run() {
        while(true){
        PointerInfo info = MouseInfo.getPointerInfo();
        Point pp=info.getLocation();
        System.out.println(pp);
            try {
                sleep((int)(Math.random() * 1000));
            } catch (InterruptedException e) {}
        }
       
    }
}
public class MyMouse{
    public static void main(String[] ss) {
        new ShowMyMouse("Mouse Pointer info").start();
    }
}
Share:

Zoom in out in html5 Canvas


This is the part of HTML5 Animation. if you want to ZOOM IN and ZOOM OUT in some intervals continuously. then you can use HTML5 canvas. Listed below the code that will ZOOM IN and ZOOM OUT to any image which you want.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="js/jquery-2.1.1.js"></script>
</head>
<body onLoad="drawCanvas();">
    <div>
        <canvas id="myCanvas" width="634" height="378">
            <p>Your browser doesn't support canvas.</p>
        </canvas>
    </div>
</body>
<script>
var surface; var happy; var x = 50; var y = 50; var scale = 0; var scaleDirection = 0.2;
function drawCanvas() {
    surface = document.getElementById("myCanvas");
    if (surface.getContext) {
        happy = new Image();
        happy.onload = loadingComplete;
        happy.src = "Voayger_voyageofdiscovery.jpg";
    }
}
function loadingComplete(e) {
    setInterval(loop, 125);
}
function loop() {
    var surfaceContext = surface.getContext('2d');
    surfaceContext.fillStyle = "rgb(255,255,255)";
    surfaceContext.fillRect(0, 0, surface.width, surface.height);
    // Save the current context
    surfaceContext.save();
    // Translate to the center point of our image
    surfaceContext.translate(x + happy.width * 0.5, y + happy.height * 0.5);
    // Perform the scale
    surfaceContext.scale(scale, scale);
    // Translate back to the top left of our image
    surfaceContext.translate(-happy.width * 0.5, -happy.height * 0.5);
    // Finally we draw the image
    surfaceContext.drawImage(happy, 0, 0);
    // And restore the context ready for the next loop
    surfaceContext.restore();
    // Animate our scale value
    scale += scaleDirection;
    if (scale < 0.2 || scale > 2) {
        scaleDirection = -scaleDirection;
    }
}
</script>
</body>
</html>
 



Share:

Fill and Empty SELECT box in jquery

Fill and Empty SELECT box in jquery




If you fill combobox from database in html and ajax jquery.
 ajax jquery transfer datas from database and you needed to put those datas into select box. Before this you need to clear existing datas from select combo box then you will use “empty()” and “apped()” to use fill the data. Use listed below codes to achieve that.
====================================================
<script src="jquery-1.6.3.min.js" language="javascript" type="text/javascript"></script>
<select name="myNum" Id="myNum" >
    <option value="0"><-- Select --></option>
</select>
<br/>
<input type="button" id="myadd" name="myadd" value="Add"/>
<script>
$(function(){
$("#myadd").click(function() {
        $('#myNum').empty();
        var i;
        for(i=0;i<=10;i++) {
               $('#myNum').append('<option value="' + i + '">' +i + '</option>');  
        }
    });
});
</script>
Share:

Incompatible type required: org.hibernate.Session found: javax.mail.Session Java mail struts and hibernate at the same time



      Incompatible type required: org.hibernate.Session found: javax.mail.Session Java mail struts and hibernate at the same time.



When you work with hibernate in java and want to use java email then you will face
the error, incompatible type required: org.hibernate.Session found: javax.mail.Session
This is because Session is in both package, so you needed to explicit declaration.
Use the listed below email code in java hibernate and you will not face the above error.
------------------------------------------------------

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import org.hibernate.Query;
public void sendEmailToAll(String toEmail){
        String ffrom = "POP@mail.com";
        String tto = toEmail;
        String ssubject = "My subject" + new Date();
        String msgText = "My text message ";
        Properties properties = new Properties();
        properties.put("mail.smtp.host", "my email ip");
        javax.mail.Session ss = javax.mail.Session.getDefaultInstance(properties,null);
        try {
            MimeMessage message = new MimeMessage(ss);
            message.setFrom(new InternetAddress(ffrom));
            message.setRecipient(Message.RecipientType.TO, new InternetAddress(tto));
            message.setSubject(ssubject);
            message.setSentDate(new Date());
            MimeBodyPart messagePart = new MimeBodyPart();
            messagePart.setText(msgText);
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messagePart);
            message.setContent(multipart);
            Transport.send(message);
        } catch (MessagingException e) {
            System.out.println(e.toString());
        }
    }
 





Share:

Convert English Words to Hindi Words


Convert English Words to Hindi Words



Some time you have make a code that will convert the English words to Hindi words. This is called 
transliteration as you seen in many news paper web sites. They provide a form to send comments in Hindi or English. Listed below the code that will transliterate English word to Hindi words.
I have used Google transliteration.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://www.google.com/jsapi"> </script>
<script type="text/javascript">
// Load the Google Transliteration API
google.load("elements", "1", {
            packages: "transliteration"
          });
function onLoad() {
    var options = {
        sourceLanguage:
                google.elements.transliteration.LanguageCode.ENGLISH,
            destinationLanguage:
                [google.elements.transliteration.LanguageCode.HINDI],
            shortcutKey: 'ctrl+g',
            transliterationEnabled: true
    };
    // Create an instance on TransliterationControl with the required options.
    var control =new google.elements.transliteration.TransliterationControl(options);
    // Enable transliteration in the textbox with id 'transliterateTextarea'.
        control.makeTransliteratable(['firstName']);
        control.makeTransliteratable(['lastName']);
      }
      google.setOnLoadCallback(onLoad);
      </script>
</head>
<body>
<input type="text" autocomplete="OFF" class="tb4" id="firstName" name="firstName">
<input type="text" autocomplete="OFF" class="tb4" id="lastName" name="lastName">
</body>
</html>
 










Share:

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip