|
You last visited: Today at 15:55
Reader with code source
04/28/2012, 01:25
|
#1
|
elite*gold: 0
Join Date: Apr 2012
Posts: 134
Received Thanks: 30
|
Reader with code source
it's reader with code source , nothing fancy , some methods of copy,past,cut,select,delete,read,readAndClean also catching ctrl+a to select all , ctrl+r to read
it read throw instance of SpVoice at SpeechLib. , it's voice is so damn weird and talking pretty fast but it helps me when im multi tasking or too lazy to read :P
feel free to correct any mistakes in the code (if there :P)
it may not be the best way to get it done but im still learning
code source
P.S add the SpeechLib as ref. u will find it at COMponent refs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
namespace Reader
{
public partial class Form1 : Form
{
public Form1(){InitializeComponent();}
string toread;
void talk(string tosay){
SpVoice voice = new SpVoice();voice.Volume = 100;
voice.Speak(tosay, SpeechVoiceSpeakFlags.SVSFDefault);}
private void readToolStripMenuItem_Click(object sender, EventArgs e){
if (textBox1.SelectedText == "")toread = textBox1.Text;else toread = textBox1.SelectedText;talk(toread);}
private void readAndCleanToolStripMenuItem_Click(object sender, EventArgs e){
if (textBox1.SelectedText == "")toread = textBox1.Text;
else toread = textBox1.SelectedText;talk(toread);textBox1.Text = "";}
private void readOnlyToolStripMenuItem_Click(object sender, EventArgs e){
if (textBox1.SelectedText == "")toread = textBox1.Text;
else toread = textBox1.SelectedText;talk(toread);}
private void selectAllToolStripMenuItem1_Click(object sender, EventArgs e){
textBox1.SelectionStart = 0;textBox1.SelectionLength = textBox1.TextLength;}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e){
if (e.KeyChar == (char)1){textBox1.SelectionStart = 0;textBox1.SelectionLength = textBox1.TextLength;}
if (e.KeyChar == (char)18){readOnlyToolStripMenuItem_Click(this.textBox1, e);}}
private void deselectAllToolStripMenuItem_Click(object sender, EventArgs e){textBox1.SelectionLength = 0;}
private void deleteAllToolStripMenuItem_Click(object sender, EventArgs e){textBox1.SelectedText = "";}
private void deleteSelectedToolStripMenuItem_Click(object sender, EventArgs e){textBox1.SelectedText = "";}
private void deleteAllToolStripMenuItem1_Click(object sender, EventArgs e){textBox1.Text = "";}
private void cutSelectedToolStripMenuItem_Click(object sender, EventArgs e){
Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText);textBox1.SelectedText = "";}
private void cutToolStripMenuItem_Click(object sender, EventArgs e){
try { Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText); textBox1.SelectedText = ""; }catch { };}
private void cutAllToolStripMenuItem_Click(object sender, EventArgs e){
Clipboard.SetText(textBox1.Text, TextDataFormat.UnicodeText);textBox1.Text = "";}
private void copyAllToolStripMenuItem_Click(object sender, EventArgs e){Clipboard.SetText(textBox1.Text, TextDataFormat.UnicodeText);}
private void copySelectedToolStripMenuItem_Click(object sender, EventArgs e){
Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText);}
private void copyToolStripMenuItem_Click(object sender, EventArgs e){
Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText);}
private void pasteToolStripMenuItem1_Click(object sender, EventArgs e){textBox1.Paste(Clipboard.GetText());Clipboard.Clear();}
}
}
i don't use spaces at methods so i can see as many as possible (sorry if u don't like it that way or not used to it like that  )
P.S design is just strip menu and textbox , ill upload it anyway
for ss
|
|
|
04/28/2012, 09:53
|
#2
|
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 782
|
Messy code.
|
|
|
04/28/2012, 11:07
|
#3
|
elite*gold: 0
Join Date: Apr 2012
Posts: 134
Received Thanks: 30
|
yup that's true , wish to do it better next time
|
|
|
04/28/2012, 18:02
|
#4
|
elite*gold: 0
Join Date: Mar 2005
Posts: 1,303
Received Thanks: 1,355
|
you should really label your functions and uses spaces in them  & seperate lines
|
|
|
04/28/2012, 19:11
|
#5
|
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,872
|
Good code first starts with legibility.
|
|
|
04/28/2012, 21:31
|
#6
|
elite*gold: 20
Join Date: Jun 2006
Posts: 3,293
Received Thanks: 918
|
You may be able to see as much as possible this way but is it of any use when it's ridiculously hard to read?
|
|
|
04/28/2012, 23:26
|
#7
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,122
Received Thanks: 2,490
|
Well i glanced at your code, and i havent got a ******* clue what it does. Which is awkward cos if it was written properly it would be simple im sure.
My Advice, if you wanna see more of you code at the same time, get a bigger screen
|
|
|
04/29/2012, 02:25
|
#8
|
elite*gold: 0
Join Date: Apr 2012
Posts: 134
Received Thanks: 30
|
i thought this was clear enough to read but maybe you are not used to read it like that so to simplify this , here is the style you used to read
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
namespace Reader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string toread;
void talk(string tosay)
{
SpVoice voice = new SpVoice();
voice.Volume = 100;
voice.Speak(tosay, SpeechVoiceSpeakFlags.SVSFDefault);
}
private void readToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectedText == "")
toread = textBox1.Text;
else toread = textBox1.SelectedText;
talk(toread);
}
private void readAndCleanToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectedText == "")
toread = textBox1.Text;
else toread = textBox1.SelectedText;
talk(toread);
textBox1.Text = "";
}
private void readOnlyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectedText == "")
toread = textBox1.Text;
else toread = textBox1.SelectedText;
talk(toread);
}
private void selectAllToolStripMenuItem1_Click(object sender, EventArgs e)
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.TextLength;
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)1)
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.TextLength;
}
if (e.KeyChar == (char)18)
{
readOnlyToolStripMenuItem_Click(this.textBox1, e);
}
}
private void deselectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectionLength = 0;
}
private void deleteAllToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectedText = "";
}
private void deleteSelectedToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectedText = "";
}
private void deleteAllToolStripMenuItem1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}
private void cutSelectedToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText);textBox1.SelectedText = "";
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
try {
Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText); textBox1.SelectedText = "";
}
catch { };
}
private void cutAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBox1.Text, TextDataFormat.UnicodeText);textBox1.Text = "";
}
private void copyAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBox1.Text, TextDataFormat.UnicodeText);
}
private void copySelectedToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText);
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBox1.SelectedText, System.Windows.Forms.TextDataFormat.UnicodeText);
}
private void pasteToolStripMenuItem1_Click(object sender, EventArgs e)
{
textBox1.Paste(Clipboard.GetText());Clipboard.Clear();
}
}
}
the first style wasn't meant to be more complicated but to be able to trace the whole thing without searching for definitions or refs
@hybird @kyn @kov @ulti @buss , is it clear enough now  ?
P.S at read and clean , if u selected some text to read and clean it will read what u selected and clean all
how to fix
Quote:
if (textBox1.SelectedText == "")
toread = textBox1.Text;
else toread = textBox1.SelectedText;
talk(toread);
textBox1.Text = "";
|
change the textBox1.Text = ""; to textBox1.SelectedText = "";
thanks everyone , wish i do it better on the next project , back to books ^^
|
|
|
All times are GMT +2. The time now is 15:55.
|
|