Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
New Feature: Community Sites:
Create your own .NET community website and start earning from Google AdSense !
It's Free !
|
Change the Color of Text Content
Posted Date:
30 Aug 2008
Total Responses:
6
|
Posted By: Pooja Member Level: Silver Points: 1
|
Hi Friends,
I have implemented the search engine concept in my application. I need to change the color & back color of a particular searched text in a page with out change the label or textbox color at page load event of a code behind. How can I do this ??
Reply Immediately !!!! It's very Urgent !!!
|
Responses
|
| Author: Pradeep Kumar Chaudhary 30 Aug 2008 | Member Level: Gold | Rating: Points: 4 | You just write css for those particular field where you want to display your search text. eg; #content{ text-align: center; color: #00CCFF; font-family: arial; background:#CC6600; } This will work properly, if u have any queries feel free to post them.
Regard, Pradeep
| | Author: Pooja 30 Aug 2008 | Member Level: Silver | Rating: Points: 4 | hi pradeep,
I think you didn't understand my question. because I want to apply particular text in my page content. like, If a label contains the below text : India is a peaceful country ...
here I want to change the color of a text "India" How it possible ???
any way thanks for your css coding!!!
| | Author: saroop 31 Aug 2008 | Member Level: Silver | Rating: Points: 3 | take the text to a string variable
use the substring to take the necessary part
and apply html formatting to change the color
use inline styles
it works
| | Author: Gaurav Agrawal 31 Aug 2008 | Member Level: Gold | Rating: Points: 6 | Using CSS to provide the visual formatting for your HTML files has a number of distinct advantages. It will free up your creativity to put together really beautiful presentation of your content, while protecting the structure of the information.
It is important though, while working on the design, not to forget that mistakes in your choice of colour, font size and imagery could make your content inaccessible. This page will help you to avoid many of the pitfalls.
CSS is compliant with the latest technologies, such as extensible HTML (XHTML). It works together with Dynamic HTML (dHTML) and JavaScript. CSS files can be read and used by other languages and applications.
As a bonus, the fact that most web sites could use a single style sheet to format all web pages means that CSS dramatically reduces the cost of site maintenance and makes global changes to the look and feel of the site very much more feasible.
Another consideration is that, increasingly, people are using their own personal Style Sheets to format web pages to meet their specific needs, for example to increase the font size or change the colour and contrast. However, these are made less useful if web designers use values and settings that cannot be overridden. Techniques
* Defining colours in CSS - can be great fun: not only do you have thousands to choose from, but you get a wide variety of ways to describe your selection:
The colour blue, for instance can be defined as:
blue (the colour name)
#0000ff (the red, green and blue (RGB) values in hexadecimal)
or the short form: #00f
or rgb(0,0,255) (the RGB values in decimal).
The predefined colour names are: black, aqua, blue, fuchsia, grey, green, lime, maroon, navy, olive, purple, red, silver, yellow, teal and white, In addition, transparent is also a valid property value.
Colours are declared by defining values for color and background-color properties.
You can apply the color and background-color properties to most HTML elements, including body, which will change the colours of the whole page unless other elements are given a different background.
It’s important to remember to define both the background and font colors, if text is to appear in an element with a coloured background. Some users need to define a colour scheme to make the screen comfortable to read, and their defined background could be the same as your defined font colour, making text impossible to read.
The colour combinations you select, and providing a good contrast between the text and background colours you use, is important for a lot of users. People who are colour blind or have one of a wide range of other sight conditions, will find it much easier to read your pages if you choose carefully. If there is ever an instance where you need a more subtle contrast, you must make sure that the text is large enough and bold enough to be read easily in spite of the softer contrast.
In addition, don't forget to remove all formatting code from your HTML if you are making changes to an existing web site, as formatting left in the HTML code can override your CSS styling and also makes it very difficult for users to define their own preferences. . Formatting should be either all in the CSS or entirely in the HTML code, not split between the two.
* Font type - Choosing a font is a relatively simple task, and you may want to make a distinction in the fonts for different elements on the page. This shouldn’t be overdone though otherwise it could interfere with the flow of reading the content.
As you can never be certain which fonts your users will have on their computers, it’s important to give some alternatives too. Then, if the font you have selected isn’t available, the browser may use another, similar one.
An example of code in your CSS could look like this:
body {
font-family: Verdana, Helvetica, Geneva, Arial, sans-serif;
color: black;
background-color: #d8da3d;
}
h1 {
font-family: Georgia, "Times New Roman", Times, serif;
color: purple;
background-color: none;
}
* Property size - Property size values wherever possible, should be defined in flexible, relative terms. As the sample style sheet shows:
body {
font-size: 100%;
margin: 3em;
}
table {
width: 100%;
}
tr {
line-height: 110%
}
Note that it isn't only the font size that is defined in relative terms, but also selectors that may contain text. This ensures that when users select larger or smaller text size settings in their browser to suit their reading requirements, container sizes will scale accordingly and not force the larger text into a space that is too small for it.
* Font-size property values - These should be chosen with care to ensure that the text will scale properly. Set the base size of your BODY element to 101% (or equivalent: 1.01em, ex, or medium) to ensure that it will be displayed at a close approximation of the user's chosen text size setting. This will also make sure that an Internet Explorer error that occurs when the base font is specified at less than 100%, or 1em, is not triggered. This error compounds the difference between font sizes, which can result in either unintentionally extra small or extra large text.
If you want your text displayed in a font size smaller than the browser default medium, it is best to define the container elements individually, but be wary of compounding one size on top of another, as the rules of inheritance mean that the property value of a parent selector will be applied to its child selectors. In other words, if you apply an 80% value to a TABLE selector and again to a TD selector, the result in CSS compliant browsers will be a font size of 64%. This may be difficult to read, but could become impossible for people who normally have their browser text size set to smallest.
* Inserting background images - This involves several properties, and you will still need to provide an appropriate background colour, in case the user has images turned off in their browser, as the text colour you have chosen may not provide a good contrast against their browser default background colour. The filepath to the image must be referenced in full; then you need to define how often and where the image should appear. So the CSS may be:
body {
background-color: white,
background-image: url(http://www.yoursite.c.uk/images/bgrnd.gif);
background-repeat: no-repeat
background-position: top center;
}
The background-repeat property defines whether and how the image is repeated within its containing element (in this case the page itself). The options are:
- repeat (equivalent to a solid or tiled effect throughout the whole page),
- repeat-y (repeating on the 'y-axis', creating a vertical strip),
- repeat-x (repeating on the 'x-axis', making a single horizontal strip),
- no-repeat (which displays only one instance of the image).
The background-position property value defines where to position the first instance of the image, the most commonly used options are: top, center, bottom, left, right or a combination of vertical and horizontal positions, e.g. top right.
Be careful in your choice of images as backgrounds in CSS though, as there is no opportunity to provide an ALT attribute if the image is conveying a message, so users who cannot see the screen will not be able to know what that information is. In particular, images of text should not be displayed as background unless the same text is available close to the image. This could be presented as transparent text behind the image therefore making it available to screen readers, braille displays and text browsers but invisible, and therefore not repeated, to the eye. Also ensure that there is sufficient contrast against text and that the image will not make content difficult to read.
* Allow user override of your formatting - The most common changes that may be required are to make font sizes bigger or change the colours and contrast to suit an individual's needs, so unless there is a good reason to define these as "important", avoid doing so. * Choose wording carefully - to avoid making colour, or format-specific, comments like “Follow the instructions in red” or “important information is highlighted in bold”. These will be meaningless if the relevant style settings are disabled or overridden by the user and are irrelevant to anyone who cannot see the screen or who is using a monochrome or small screen device, such as a PDA (Personal Digital Assistant).
Testing tips
Font sizes must be flexible i.e. em, %, smaller etc not pt or px., images should be visible / readable when CSS is removed. If any of the text, link or background colours are defined, all of the other colours should also be defined. Read content looking for any information that would not be understood by people who cannot see, or distinguish colour.
* Automated tools - Tools can pick up on fixed font sizes.
* Accessibility toolbar – CSS - Show Style Sheet. This will display the content of any linked CSS style sheets. Search for Absolute units: "pt" "px" etc, search for "line-height" and ensure that it has not been defined using absolute values. CSS - Disable CSS. Toggles CSS off and on to ensure that the page makes sense without the CSS formatting and that images do not interfere with the legibility of text. CSS - Show Style Sheet. This will show any linked CSS style sheets. Search for "color" and make sure that if either text or background is defined, that they both are.
* Browser - View - Source. Edit - Find - "css" AND Source. Edit - Find - "style". This can show if inline CSS styles are being used also search for "line-height". To make sure that tables, DIVs etc will expand to accommodate larger text sizes: View - Text Size - "Largest" and “Smallest”. Tools - Internet Options - Accessibility check "Ignore colours on the page" to ensure that images are still readable. View - Source. Edit - Find "color" and "font" to ensure that formatting has been removed from the HTML pages.
| | Author: Gaurav Agrawal 31 Aug 2008 | Member Level: Gold | Rating: Points: 6 | u can help by this code
// Test.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text HWND hListBox,hButton; // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK ListWndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); int ChangeColor=0; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_TEST, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage is only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TEST); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_TEST; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); FARPROC lpfnChildWndProc_New; int iIndex,iLength,Res; TCHAR *pVarName; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case ID_LIST: { if(wmEvent == LBN_SELCHANGE) { hdc = BeginPaint(hListBox, &ps); Res=SetTextColor(hdc,RGB(155, 234, 245)); iIndex = SendMessage (hListBox, LB_GETCURSEL, (WPARAM)0,(LPARAM) 0) ; iLength = SendMessage (hListBox, LB_GETTEXTLEN, iIndex, 0) + 1 ; pVarName = new TCHAR[iLength] ; strcpy(pVarName,""); SendMessage (hListBox, LB_GETTEXT, iIndex, (LPARAM) pVarName) ; MessageBox(hWnd,pVarName,"Selected Item",MB_OK); } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... SetTextColor(hdc,RGB(0,0,255)); RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_CREATE: { int index; hListBox=CreateWindow("LISTBOX",NULL, WS_CHILD|WS_HSCROLL|LBS_STANDARD,0,10,150,200,hWnd,(HMENU)ID_LIST,(HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE),,NULL); hButton=CreateWindow("BUTTON","Button", WS_CHILD|WS_VISIBLE|WS_BORDER,200,10,150,200,hWnd,(HMENU)ID_LIST,(HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE),,NULL); lpfnChildWndProc_New = (FARPROC)MakeProcInstance((FARPROC)ListWndProc, hInst); // SetWindowLong(hListBox,GWL_WNDPROC,(DWORD)lpfnChildWndProc_New); ::ShowWindow(hButton,SW_SHOW); ::UpdateWindow(hButton); ::ShowWindow(hListBox,SW_SHOW); ::UpdateWindow(hListBox); CHAR string[10]; // for(int i=0;i<20;i++) { // _itoa(i,string,10); // SendMessage(hListBox,LB_ADDSTRING,(WPARAM)100,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); // int len=strlen("India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabadajfndjgninhkn lt,mnkjnknknvknkf"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara "); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"1"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"2"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"3"); ChangeColor=1; SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"dsads.................................................................."); ChangeColor=0; SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India.................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India...................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); ChangeColor=1; SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India........"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"5"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"7"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"9"); ChangeColor=0; SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"Zndia Hamara India, Jai Hind, Ingulab Zindabad....................................................................this is the max string"); SendMessage(hListBox,LB_SETHORIZONTALEXTENT,(WPARAM)500,(LPARAM)0); SetWindowLong(hListBox,GWL_WNDPROC,(DWORD)lpfnChildWndProc_New); // iIndex = SendMessage (hListBox, LB_SETCURSEL, (WPARAM)5,(LPARAM) 0) ; // iIndex = SendMessage (hListBox, LB_SETCURSEL, (WPARAM)0,(LPARAM) 0) ; } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); int iIndex,iLength,Res; TCHAR *pVarName; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case ID_LIST: { if(wmEvent == LBN_SELCHANGE) { iIndex = SendMessage (hListBox, LB_GETCURSEL, (WPARAM)0,(LPARAM) 0) ; iLength = SendMessage (hListBox, LB_GETTEXTLEN, iIndex, 0) + 1 ; pVarName = new TCHAR[iLength] ; strcpy(pVarName,""); SendMessage (hListBox, LB_GETTEXT, iIndex, (LPARAM) pVarName) ; MessageBox(hWnd,pVarName,"Selected Item",MB_OK); } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; // case WM_LBUTTONDOWN: // MessageBox(hWnd,"Button Down","Button Down",MB_OK); // break; case WM_PAINT: /* hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... if(ChangeColor) SetTextColor(hdc,RGB(155, 234, 245)); else SetTextColor(hdc,RGB(255,0,255)); RECT rt; GetClientRect(hWnd, &rt); //DrawText(hdc, "Test", strlen("Test"), &rt, DT_CENTER); EndPaint(hWnd, &ps);*/ hdc = BeginPaint (hWnd, &ps) ; SetTextColor(hdc,RGB(255,0,255)); EndPaint (hWnd, &ps) ; break; case WM_DESTROY: PostQuitMessage(0); break; case WM_CREATE: { SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabad...................................................................."); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara India, Jai Hind, Ingulab Zindabadajfndjgninhkn lt,mnkjnknknvknkf"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"India Hamara "); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"1"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"2"); SendMessage(hListBox,LB_ADDSTRING,(WPARAM)0,(LPARAM)"3"); break; } default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
| | Author: Pooja 02 Sep 2008 | Member Level: Silver | Rating: Points: 4 | hi friends,
I got the solution with in a single line. I think somebody was not clearly understood my requirement. any way thanks for the reply!!! below is the solution code.
dataValue.Replace(searchStr, "<span style='color:red;'><B><I>" + searchStr + "</I></B></span>");
Ragards Pooja.M
|
| Post Reply |
|
|
|
You must Sign In to post a response.
|
|
|
|